问题
I can't seem to get round this issue. I just cannot sign in.
I'm running the BasicSensorApi sample file and it just will not connect. It seems i'm getting RESULT_CANCELED even though i select an account on the dialog?
Here is the end of my logcat running on a OnePlus One 4.4.
Any ideas on what i need to do?
(The Google console is set up with 'net.xx', correct SHA1, Fitness APi enabled.
01-26 15:54:06.838 15678-15678/net.xx D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-26 15:54:06.888 15678-15678/net.xx I/BasicSensorsApi﹕ Ready
01-26 15:54:06.898 15678-15678/net.xx I/BasicSensorsApi﹕ Connecting...
01-26 15:54:07.008 15678-15678/net.xx D/OpenGLRenderer﹕ Enabling debug mode 0
01-26 15:54:07.018 15678-15678/net.xx I/BasicSensorsApi﹕ Connection failed. Cause: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{41c147e8: android.os.BinderProxy@41c14788}}
01-26 15:54:07.458 15678-15678/net.xx I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@418ce750 time:11713882
01-26 15:54:09.898 15678-15678/net.xx I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@418ce750 time:11716323
回答1:
If you're not signed in you will get a callback to GoogleApiClient.OnConnectionFailedListener()
with the error shown in your LogCat message. If you then try to resolve the problem using
result.startResolutionForResult(YourActivity.this, REQUEST_CODE);
the account selector dialog is displayed. Sounds to me that this is how far you've come. Is that correct?
Once you've selected an account in the dialog you need to make another connection attempt from your activity's onActivityResult()
. Sounds to me like you might be missing this piece code.
On a side note: If this is the very first time you connect you will at this point get another error. Resolving that one will show the consent screen. If the user accepts, and you make yet another connection attempt you should be successfully connected to the API.
回答2:
When trying to resolve this sign-in loop while adding Google Plus to Google Play services mapping, I had to add an additional API and OAuth credential for my Android app on the Google APIs console.
I already had a token credential tied to my app for the Maps APIs, but Google Plus login would return a CANCELED result code until I added the Google Plus APIs and added the required OAuth credentials for those APIs. As soon as it was in place for my APIs project, my activity result handler started seeing OK result codes.
来源:https://stackoverflow.com/questions/28154332/android-google-fit-onconnectionfailed-sign-in-required