Не авторизуется через Google аккаунт в приложении
Делаю авторизацию через аккаунт гугл в приложении. в Firebase создала проект и добавила приложение указав название, пакет и SHA-1.
Когда нажимаю кнопку авторизации выбираю свою учетную запись далее появляется диалоговое окно и зависает. В логах пишет следующее:
2020-02-25 21:31:03.222 1635-2367/? D/PopupCameraManagerService: onForegroundInfoChanged foregroundInfo ForegroundInfo{mForegroundPackageName='myapp.testapp', mForegroundUid=10262, mForegroundPid=10349, mLastForegroundPackageName='com.google.android.gms', mLastForegroundUid=10183, mLastForegroundPid=8562, mMultiWindowForegroundPackageName='null', mMultiWindowForegroundUid=-1, mFlags=0} 2020-02-25 21:31:03.222 4256-4635/? I/ProcessMonitor: onForegroundInfoChanged: ForegroundInfo{mForegroundPackageName='myapp.testapp', mForegroundUid=10262, mForegroundPid=10349, mLastForegroundPackageName='com.google.android.gms', mLastForegroundUid=10183, mLastForegroundPid=8562, mMultiWindowForegroundPackageName='null', mMultiWindowForegroundUid=-1, mFlags=0} 2020-02-25 21:31:03.222 4256-4635/? I/GameBoosterService: onForegroundInfoChanged: Cur=myapp.testapp last=com.google.android.gms 2020-02-25 21:31:03.222 4256-4635/? D/GameBoosterService: onGameStatusChange foreground:ForegroundInfo{mForegroundPackageName='myapp.testapp', mForegroundUid=10262, mForegroundPid=10349, mLastForegroundPackageName='com.google.android.gms', mLastForegroundUid=10183, mLastForegroundPid=8562, mMultiWindowForegroundPackageName='null', mMultiWindowForegroundUid=-1, mFlags=0} 2020-02-25 21:31:03.249 10349-10923/myapp.testapp V/FA: Activity resumed, time: 586574 2020-02-25 21:31:08.336 10349-10923/myapp.testapp V/FA: Inactivity, disconnecting from the service
Код активити
public class BackupActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener {
private Button btnRestore;
private Button btnBackup;
private static final String TAG = "GPlusFragent";
private int RC_SIGN_IN = 0;
private GoogleApiClient mGoogleApiClient;
private SignInButton signInButton;
private Button signOutButton;
private Button disconnectButton;
private LinearLayout signOutView;
private TextView mStatusTextView;
private ProgressDialog mProgressDialog;
private ImageView imgProfilePic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_backup);
signInButton = (SignInButton) findViewById(R.id.sign_in_button);
signOutButton = (Button) findViewById(R.id.sign_out_button);
imgProfilePic = (ImageView) findViewById(R.id.img_profile_pic);
mStatusTextView = (TextView) findViewById(R.id.status);
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this )
.addApi(Auth.GOOGLE_SIGN_IN_API,gso)
.build();
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
});
signOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
updateUI(false);
}
});
}
});
}
@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 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);
}
}
private void handleSignInResult(GoogleSignInResult result) {
//Log.d(TAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
mStatusTextView.setText("rrrrrrrrrrrrrrr");
//Similarly you can get the email and photourl using acct.getEmail() and acct.getPhotoUrl()
if(acct.getPhotoUrl() != null)
updateUI(true);
} else {
// Signed out, show unauthenticated UI.
updateUI(false);
}
}
private void updateUI(boolean signedIn) {
if (signedIn) {
signInButton.setVisibility(View.GONE);
signOutButton.setVisibility(View.VISIBLE);
} else {
mStatusTextView.setText("4444444");
signInButton.setVisibility(View.VISIBLE);
signOutButton.setVisibility(View.GONE);
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
private void showProgressDialog() {
if (mProgressDialog == null) {
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("eeeeeeeeeee");
mProgressDialog.setIndeterminate(true);
}
mProgressDialog.show();
}
private void hideProgressDialog() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.hide();
}
}
}
