在我的Andorid应用中,我只想访问通过网络(drive.google.com)或应用与我共享的文件。我使用谷歌驱动器API访问共享文件,但我无法访问与我共享的任何文件或文件夹。我的代码如下。
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);
}
final private ResultCallback<DriveApi.MetadataBufferResult> metadataCallback =
new ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Problem while retrieving results");
return;
}
mResultsAdapter.clear();
mResultsAdapter.append(result.getMetadataBuffer());
}
};
}
注意*我们可以使用特定的文件夹名称过滤与我共享的文件或文件夹吗?
答案 0 :(得分:0)
您的应用是否有权访问共享文件? 目前Google Drive Android API仅支持FILE范围访问(请参阅详细信息here)。因此,如果您的应用无权访问这些共享文件,则不会在查询结果中收到它们。