Get notified in android app when you remotely logout (eg. in your computer web browser) from google in your google web account

Viewed 37

My android app uses google Sign In

https://developers.google.com/identity/sign-in/android/sign-in

And both login and logout works fine within the app:

protected void onCreate(Bundle savedInstanceState) {
 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}

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

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

    // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        // The Task returned from this call is always completed, no need to attach
        // a listener.
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        handleSignInResult(task);
    }
}

private void signOut() {
    mGoogleSignInClient.signOut().addOnCompleteListener(this, new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            Toast.makeText(IntroActivity.this, "Logoutcomplete", Toast.LENGTH_SHORT);
        }
    });
}


private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        String email = account.getEmail();

How can I get notified, when I logout from my device remotely from my google account: https://myaccount.google.com/device-activity

I would like to have like an event subscription so I can detect when the user's account has been removed from the device remotely.

For instance, in Gmail android app, if you are watching your mails (without touching anything in the device) and the account is signed out remotely from https://myaccount.google.com/device-activity, the app notices this event and shows that there is no user logged anymore. I want to replicate this behavior in my android app.

0 Answers
Related