2017-03-03 121 views
0

我的应用程序包含谷歌登录功能,当用户点击登录按钮,我需要使用googleapiclient获取用户名和emailId。当我运行调试APK,我得到所有必要的细节,我需要,但是,当它来释放APK,我不能够获取详细信息,而不是我得到handleSignInResult:假谷歌SignIn问题发布apk

这里是我的登入类文件的代码: -

public class SignIn extends AppCompatActivity implements 
     View.OnClickListener, 
     GoogleApiClient.OnConnectionFailedListener { 

    private static final String TAG = SignIn.class.getSimpleName(); 
    private static final int RC_SIGN_IN = 007; 

    private GoogleApiClient mGoogleApiClient; 
    private ProgressDialog mProgressDialog; 

    private SignInButton btnSignIn; 
    private Button btnSignOut, btnRevokeAccess; 
    private LinearLayout llProfileLayout; 
    private TextView txtName, txtEmail; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_signin); 

     btnSignIn = (SignInButton) findViewById(R.id.btn_sign_in); 
     btnSignOut = (Button) findViewById(R.id.btn_sign_out); 
     btnRevokeAccess = (Button) findViewById(R.id.btn_revoke_access); 
     llProfileLayout = (LinearLayout) findViewById(R.id.llProfile); 
     txtName = (TextView) findViewById(R.id.txtName); 
     txtEmail = (TextView) findViewById(R.id.txtEmail); 

     btnSignIn.setOnClickListener(this); 
     btnSignOut.setOnClickListener(this); 
     btnRevokeAccess.setOnClickListener(this); 

     GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
       .requestEmail() 
       .build(); 

     mGoogleApiClient = new GoogleApiClient.Builder(this) 
       .enableAutoManage(this, this) 
       .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
       .build(); 

     // Customizing G+ button 
     btnSignIn.setSize(SignInButton.SIZE_STANDARD); 
     btnSignIn.setScopes(gso.getScopeArray()); 
    } 


    private void signIn() { 
     Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
     startActivityForResult(signInIntent, RC_SIGN_IN); 
    } 


    private void signOut() { 
     Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
       new ResultCallback<Status>() { 
        @Override 
        public void onResult(Status status) { 
         updateUI(false); 
        } 
       }); 
    } 

    private void revokeAccess() { 
     Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
       new ResultCallback<Status>() { 
        @Override 
        public void onResult(Status status) { 
         updateUI(false); 
        } 
       }); 
    } 

    private void handleSignInResult(GoogleSignInResult result) { 
     Log.d(TAG, "handleSignInResult:" + result.isSuccess()); 
     if (result.isSuccess()) { 
      // Signed in successfully, show authenticated UI. 
      GoogleSignInAccount acct = result.getSignInAccount(); 

      Log.e(TAG, "display name: " + acct.getDisplayName()); 

      String personName = acct.getDisplayName(); 
      String email = acct.getEmail(); 

      Log.e(TAG, "Name: " + personName + ", email: " + email); 

      txtName.setText(personName); 
      txtEmail.setText(email); 

      updateUI(true); 
     } else { 
      // Signed out, show unauthenticated UI. 
      updateUI(false); 
     } 
    } 

    @Override 
    public void onClick(View v) { 
     int id = v.getId(); 

     switch (id) { 
      case R.id.btn_sign_in: 
       signIn(); 
       break; 

      case R.id.btn_sign_out: 
       signOut(); 
       break; 

      case R.id.btn_revoke_access: 
       revokeAccess(); 
       break; 
     } 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 

     // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); 
     if (requestCode == RC_SIGN_IN) { 
      GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
      handleSignInResult(result); 
     } 
    } 

    @Override 
    public void onStart() { 
     super.onStart(); 

     OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient); 
     if (opr.isDone()) { 
      // If the user's cached credentials are valid, the OptionalPendingResult will be "done" 
      // and the GoogleSignInResult will be available instantly. 
      Log.d(TAG, "Got cached sign-in"); 
      GoogleSignInResult result = opr.get(); 
      handleSignInResult(result); 
     } else { 
      // If the user has not previously signed in on this device or the sign-in has expired, 
      // this asynchronous branch will attempt to sign in the user silently. Cross-device 
      // single sign-on will occur in this branch. 
      showProgressDialog(); 
      opr.setResultCallback(new ResultCallback<GoogleSignInResult>() { 
       @Override 
       public void onResult(GoogleSignInResult googleSignInResult) { 
        hideProgressDialog(); 
        handleSignInResult(googleSignInResult); 
       } 
      }); 
     } 
    } 

    @Override 
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 
     // An unresolvable error has occurred and Google APIs (including Sign-In) will not 
     // be available. 
     Log.d(TAG, "onConnectionFailed:" + connectionResult); 
    } 

    private void showProgressDialog() { 
     if (mProgressDialog == null) { 
      mProgressDialog = new ProgressDialog(this); 
      mProgressDialog.setMessage(getString(R.string.loading)); 
      mProgressDialog.setIndeterminate(true); 
     } 

     mProgressDialog.show(); 
    } 

    private void hideProgressDialog() { 
     if (mProgressDialog != null && mProgressDialog.isShowing()) { 
      mProgressDialog.hide(); 
     } 
    } 

    private void updateUI(boolean isSignedIn) { 
     if (isSignedIn) { 
      btnSignIn.setVisibility(View.GONE); 
      btnSignOut.setVisibility(View.VISIBLE); 
      btnRevokeAccess.setVisibility(View.VISIBLE); 
      llProfileLayout.setVisibility(View.VISIBLE); 
     } else { 
      btnSignIn.setVisibility(View.VISIBLE); 
      btnSignOut.setVisibility(View.GONE); 
      btnRevokeAccess.setVisibility(View.GONE); 
      llProfileLayout.setVisibility(View.GONE); 
     } 
    } 
} 

,这里是

handleSignInResult:false 
+1

请参阅本http://stackoverflow.com/q/35561657/2809326 – arjun

+0

请参阅此[链接](http://stackoverflow.com/a/27639043/6092099)并在Google控制台中替换您的SHA-1。 –

回答

0

检查你的文件谷歌 - service.json发布APK的日志报告

必须从release.keystore添加SHA1不android_debug.keystore

+0

如何从release.keystore生成SHA1 @Hoang Duc Tuan – Karthik

+0

这里http://stackoverflow.com/questions/34933380/sha1-key-for-debug-release-android-studio-mac –

+0

Thanx @Hoang Duc Tuan。你拯救了我的一天。 – Karthik