Home » Android » Google Drive Android API tutorial issue

Google Drive Android API tutorial issue

Posted by: admin June 15, 2020 Leave a comment

Questions:

Following this tutorial, I pasted this code into my Main Activity:

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
    }
}

I end up having to import a buncha libraries, but I still can’t fix this error:

RESOLVE_CONNECTION_REQUEST_CODE cannot be resolved to a variable

any ideas??? I can’t figure out which library contains this constant…

How to&Answers:

Turns out when the tutorial specifies to start with an android project, they mean a Google Drive android project, which has different imports and class definitions, which aren’t made clear from the tutorial. They actually give some starter code for a Google Drive android project, but they mislabeled it as just a “Android Quickstart” so I assumed it was no different from any other android project.

enter image description here

Here’s where the link goes: Google Drive Android Quickstart, and the tutorial makes alot more sense if you use this code as a reference.

If anybody is curious what the fix to the original issue is, the constant should actually be
REQUEST_CODE_RESOLUTION, but again, there are alot more changes so just use the Google Drive Android Quickstart