Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Google Sign In Dialog Not Cancelable

I am using Firebase for my Android app and have implemented Google Account Sign In. My problem is when it shows the "Choose Google Account" dialog if you click away from it it just closes. Is there a way to make this dialog not cancelable?

like image 314
Jared Avatar asked Sep 26 '16 22:09

Jared


1 Answers

First I want to make sure you take note of the reason why that behavior exists. If there is no cancel button, then how can the user change their mind? You would normally want to avoid forcing the user into something they decided later they didn't want to do.

That being said, here is my answer:

I can't say no with 100% certainty, but after looking through the API reference, I do not see that there is a way to change the default behavior of that sign in dialog.

See the API reference: https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInApi

I will suggest that the best way to deal with it is to handle it in the onActivityResult piece of your code. Just get the sign in status by calling getStatusCode() on your returned data and see if you get the SIGN_IN_CANCELLED constant. This would indicate that the user canceled which I assume would happen if they navigated away from the screen. At any rate, if that isn't the code returned, just print it in your console and see which code is returned when you click off and cancel the dialog.

Then, if they did cancel, you can either restart the screen or ask them what happened. I would recommend the latter to avoid forcing them into a situation where the only way to get what they want is to force close your app.

Edit:

Here is an example from the docs about checking that status code. Might be better to do it this way than by pulling the status object and getting it's code that way:

@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);
    }
}
like image 76
Ryan Avatar answered Sep 19 '22 02:09

Ryan