I'm trying to use the Google Drive API to allow the user to select a file and (so far) get the metadata of it.
Here's where I'm at (extracted):
@Override
public void onConnected(Bundle connectionHint) {
super.onConnected(connectionHint);
IntentSender intentSender = Drive.DriveApi
.newOpenFileActivityBuilder()
.build(getGoogleApiClient());
try {
startIntentSenderForResult(
intentSender, REQUEST_CODE_OPENER, null, 0, 0, 0);
} catch (SendIntentException e) {
Log.w(TAG, "Unable to send intent", e);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_OPENER:
if (resultCode == RESULT_OK) {
if (data != null) {
DriveId driveId = data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
Log.d(TAG, "driveId = " + driveId.encodeToString());
//driveId.asDriveResource().getMetadata(getGoogleApiClient())
driveId.asDriveFile().getMetadata(getGoogleApiClient())
.setResultCallback(new ResultCallback<DriveResource.MetadataResult>() {
public void onResult(@NonNull DriveResource.MetadataResult mdr) {
// Never gets here
}
});
}
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
Seems to work just fine. It logs the DriveId
it finds and gets to the getMetadata()
call. But it never calls the callback: onResult()
is never reached.
I feel like I'm almost certainly doing something obvious wrong, but in studying the API documentation and the Google example code, I can't spot what it is.
Edited to add:
I tried changing it from using setResultCallback()
to await()
(in a thread), but while the DriveID
is again fine, the MetadataResult
has a statusCode
of CANCELED
(even though I click SELECT from the Drive file picker). So calling getMetadata()
on it returns null
.
Does this suggest further where things might be going wrong?