在我的Andorid應用程序中,我只想訪問通過web(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());
}
};
}
注*我們可以過濾與我分享了一個特定的文件夾名稱的文件或文件夾?
你說「我無法訪問與我共享的任何文件或文件夾」。您的意思是GoogleDrive文件夾和文件是否由他人擁有,並與您分享? –
@qbix是的,我想訪問谷歌驅動器文件夾和其他擁有,但與我共享的文件。 – Sirconrad
[此相關問題]的答案(http://stackoverflow.com/questions/26929154/unable-to-get-the-shared-with-me-files-with-the-google-drive-api-using- filters-s?lq = 1)表示Android GoogleDrive API不支持訪問共享文件,即使存在查詢選項。當你運行你的查詢時,你會得到任何結果嗎? –