我试图使用Google Drive API来允许用户选择一个文件,并且(到目前为止)获取它的元数据。Android:Google Drive getMetaData()不调用回调
下面是我在哪里(提取):
@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);
}
}
似乎工作得很好。它记录它找到的DriveId
,并获取到getMetadata()
呼叫。但它永远不会调用回调:onResult()
永远不会到达。
我觉得我几乎肯定会做出明显错误的事情,但在研究API文档和Google示例代码时,我无法发现它是什么。
编辑补充:
我试图用setResultCallback()
到await()
(在一个线程)改变它,但同时DriveID
再次精细,MetadataResult
有CANCELED
一个statusCode
(即使我按SELECT从Drive文件选择器)。所以打电话给getMetadata()
返回null
。
这是否表明事情可能出错?
谢谢。对不起,我没有更清楚:为了简化示例,我删除了实际的'onResult'代码,并将其替换为该注释,因为执行从未到达任何地方。在我给出的例子中,如果我将代码放在那里,它永远不会检查'isSuccess()'。 –