我的应用使用以下依赖项
implementation 'com.google.android.gms:play-services-auth:16.0.1'
它连接到Google Api以获取设备位置并将数据显着存储在Google Smart Lock中。
除了在运行Android 6的一台设备上运行外,它都可以正常运行。 尝试连接到Google Api时,出现以下错误:
ConnectionResult {statusCode = SERVICE_VERSION_UPDATE_REQUIRED
W / GooglePlayServicesUtil:Google Play服务已过期。需要 12800000但找到了8703448
由于Android Studio提示,我无法退回到Play服务库的早期版本
错误:所有firebase库必须高于或低于14.0.0
我应该怎么做才能使该应用程序在具有旧版Google Play服务的设备上运行?
答案 0 :(得分:1)
我通过使用此代码更新Google Play服务版本来解决了该错误,
//On button click of the google signIn
googleSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent,GOOGLE_SIGNIN_ID);
}
//onActivity Result code.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GOOGLE_SIGNIN_ID){
Task<GoogleSignInAccount> googleSignInAccountTask = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount googleSignInAccount = googleSignInAccountTask.getResult(ApiException.class);
fireBaseAuthenticationWithGoogle(googleSignInAccount);
}catch (ApiException e){
//if user doesn't have updated google play services version
if (e.getStatusCode() == 12500){
try{
// show your own AlertDialog for example:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// set the message
builder.setMessage("This app uses google play services for signing in")
.setTitle("Do you want to update?");
builder.setPositiveButton("Ok", (dialog, id) -> {
//final String appPackageName = "com.google.android.gms";
final String appPackageName = "com.google.android.gms&hl=en_IN";
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
}catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
AlertDialog dialog = builder.create();
dialog.show();
}catch (Exception err){
err.printStackTrace();
}
}
}
}
将此放置在发生异常的位置。我希望它对@matdev有帮助。