我正在使用谷歌游戏服务的静默登录,但它总是通过CompleteListener显示com.google.android.gms.common.api.ApiException: 4:'SIGN_IN_REQUIRED',但我是应用程序中的测试用户。我的代码如下,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleSignInClient = GoogleSignIn.getClient(this, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build());
}
@Override
protected void onResume() {
super.onResume();
signInSilently();
}
private void signInSilently() {
mGoogleSignInClient.silentSignIn().addOnCompleteListener(this, new OnCompleteListener<GoogleSignInAccount>() {
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
try {
GoogleSignInAccount signInAccount = task.getResult(ApiException.class);
} catch (ApiException apiException) {
System.out.println("CATE_RESULT_CODE " + apiException.getLocalizedMessage()+" " +apiException.getStatusMessage()+ " " +apiException.getMessage()+ " "+apiException.getCause() );
}
} else {
try {
GoogleSignInAccount signInAccount = task.getResult(ApiException.class);
} catch (ApiException apiException) {
System.out.println("CATE_RESULT_CODE " + apiException.getLocalizedMessage()+" " +apiException.getStatusMessage()+ " " +apiException.getMessage()+ " "+apiException.getCause() );
}
}
}
});
}
我的Gradle文件依赖:
dependencies {
ext {
support_library_version = '27.0.2'
google_play_services_version = '15.0.2'
}
implementation "com.android.support:appcompat-v7:${support_library_version}"
implementation "com.android.support:design:${support_library_version}"
implementation "com.android.support:recyclerview-v7:${support_library_version}"
implementation "com.android.support:cardview-v7:${support_library_version}"
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.google.android.gms:play-services-games:15.0.1'
}
erorr :
com.google.android.gms.common.api.ApiException: 4:
at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
at com.google.android.gms.common.internal.zzk.convert(Unknown Source)
at com.google.android.gms.common.internal.zzl.onComplete(Unknown Source)
at com.google.android.gms.common.api.internal.BasePendingResult.zza(Unknown Source)
at com.google.android.gms.common.api.internal.BasePendingResult.setResult(Unknown Source)
at com.google.android.gms.auth.api.signin.internal.zzk.zzd(Unknown Source)
at com.google.android.gms.auth.api.signin.internal.zzu.dispatchTransaction(Unknown Source)
at com.google.android.gms.internal.auth.zze.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
还需在Manifest文件中添加应用程序ID。
请给我一个解决此问题的方案。提前感谢。