Search code examples
androiddrive

Android Drive API startResolutionForResult returns RESULT_CANCELLED


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


Solution

  • 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!