Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Drive API startResolutionForResult returns RESULT_CANCELLED

Tags:

android

drive

I'm trying to implement Google Drive to my Android app and I cannot even connect to Api client. And I don't know why:

  1. I have configured project and credentials in developer console for ~/.android/debug.keystore (values seems to be correct)
  2. I have copy-pasted code from Drive for Android Documentation -> In method onConnectionFailed() I'm calling connectionResult.startResolutionForResult() if connectionResult.hasResolution()
  3. In onActivityResult for matching requestCode I'm receiving resultCode == 0 (RESULT_CANCELLED) even when i select my account

Do you have any idea why? I also tried to add:

<meta-data
    android:name="com.google.android.apps.drive.APP_ID"
    android:value="----"/>

into Manifest which is not mentioned on documentation page but on some SO posts.

Thanks for help

Edit:

I have also tried to use enableAutoManage

mGoogleApiClient = new GoogleApiClient.Builder(this)
        .enableAutoManage(this, this)
        .addApi(Drive.API)
        .addScope(Drive.SCOPE_FILE)
        .build();

instead of manualy configuring connection and connectionFailed callbacks:

        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)

It returns me error code 13 in onConnectionFailed method. Based on documentation it seems, that this returns when:

OnConnectionFailedListener passed to enableAutoManage(FragmentActivity, GoogleApiClient.OnConnectionFailedListener) when the user choses not to complete a provided resolution. For example by canceling a dialog.

But i didn't cancelled it.

I'm testing it on Nexus 5x - Android N

like image 367
VizGhar Avatar asked Jul 14 '16 09:07

VizGhar


2 Answers

I found where the problem was while reading something about wallet api

I've just needed to create OAuth client ID not API key

  1. Go to Developer Console > Credentials
  2. Click "create credentials" > OAuth client ID > Android
  3. Fill the details
  4. Create
  5. Open OAuth consent screen (on Credentials page)
  6. Fill email and product name
  7. Save

Now it works!

like image 148
VizGhar Avatar answered Nov 02 '22 17:11

VizGhar


JUST IN CASE

@VizGhar solution is right if you missed up Client ID creation process. But I get resultCode=0 and everything was fine with my OAuth client ID. And finally I solved it, so I created SHA1 as per documentation, but I run my app in debug mode (Build variant) and always had resultCode=0. Just switched to release mode and problem is gone, now resultCode=-1 as expected.

like image 24
Choletski Avatar answered Nov 02 '22 15:11

Choletski