javaandroidgoogle-signingoogle-play-games

Google play service game Silent Login error 'com.google.android.gms.common.api.ApiException: 4: '


am using google play services silent login, but it always CompleteListener show com.google.android.gms.common.api.ApiException: 4: 'SIGN_IN_REQUIRED' but am a test user in my application. My code is below,

 @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() );
                }
           }
        }
     });
  }

My gradle file dependencies :

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)

also adding app id in Manifest file.

Please give me a solution for this problem. Advance thanks


Solution

  • error will be solved...

    Anyone having this type of problem please check first your SHA 1 key from your Firebase project settings.

    My SHA 1 key is mismatched from Firebase project settings.

    Now am change that and work perfectly..

    Thank you..