public class QueryFilesSharedWithMeActivity extends BaseDemoActivity {
private ListView mResultsListView;
private ResultsAdapter mResultsAdapter;
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_listfiles);
mResultsListView = (ListView) findViewById(R.id.listViewResults);
mResultsAdapter = new ResultsAdapter(this);
mResultsListView.setAdapter(mResultsAdapter);
}
/**
* Clears the result buffer to avoid memory leaks as soon as the activity is no longer
* visible by the user.
*/
@Override
protected void onStop() {
super.onStop();
mResultsAdapter.clear();
}
@Override
public void onConnected(Bundle connectionHint) {
super.onConnected(connectionHint);
Query query = new Query.Builder()
.addFilter(Filters.sharedWithMe())
.build();
Drive.DriveApi.query(getGoogleApiClient(), query)
.setResultCallback(metadataCallback);
showMessage("Connecting ...");
}
final private ResultCallback<DriveApi.MetadataBufferResult> metadataCallback =
new ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
showMessage("onResult ...");
if (!result.getStatus().isSuccess()) {
showMessage("Problem while retrieving results");
return;
}
mResultsAdapter.clear();
mResultsAdapter.append(result.getMetadataBuffer());
showMessage("Count = "+mResultsAdapter.getCount());
}
};
}
我无法使用上述代码查询已与我共享的文件和文件夹。每当我试图查询sharedWithMe()时,我得到mResultAdapter数组计数'0'。请帮我解决这个问题。
答案 0 :(得分:1)
Android API使用Drive.File范围,这意味着您的应用可以访问由您的应用创建或显式打开的文件。其他文件不会显示在搜索结果中。
答案 1 :(得分:1)
谢丽尔是对的,您必须使用 Google API Java客户端,如下所述:
注意:Google Drive Android API目前仅支持drive.file和drive.appfolder授权范围。如果您的应用需要Drive Android API中尚未提供的其他权限或功能,则必须使用Google API Java客户端。