Android implementing Google plus login error on mConnectionResult.hasResolution()

前端 未结 1 862
借酒劲吻你
借酒劲吻你 2020-12-16 05:11

I have studied google plus login from https://developers.google.com/+/mobile/android/getting-started

When I launch my app there is a toast message \"User is connect

相关标签:
1条回答
  • 2020-12-16 05:46

    OK! So that toast is because you have signed in, and when you click you are trying to sign in again: because you don't have a connection result with an error to resolve, you get the NPE.

    This is how it works:

    1. Your sign in state is stored in Google Play services.
    2. When you connect, your app connects to Google Play services and tries to see if you have signed in before.
    3. If you have, it calls back to onConnected.
    4. If you have not, it calls back to onConnectionFailed and gives you a ConnectionResult.
    5. When the use clicks sign in, you "resolve the error" on the ConnectionResult - this is just a pending Intent which triggers the account chooser and consent screen.
    6. When the user consents, your app gets called back in onActivityResult, and you reconnect (and the flow starts again, this time ending at step 3).

    So, if you get onConnected you should hide the sign in button - the user has signed in!

    Now, perhaps for whatever reason you want the user to have to click the button to get started. That's fine too. In the onClick, you just need to test whether mPlusClient isConnected. If it is, go straight to whatever you wanted to do post sign in. If not, then resolve the connection result.

    0 讨论(0)
提交回复
热议问题