无法查询文件"与我共享"来自谷歌驱动器使用谷歌驱动器api android

时间:2014-11-18 10:39:51

标签: android google-api google-drive-api google-drive-android-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);
    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'。请帮我解决这个问题。

2 个答案:

答案 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客户端。

来源:https://developers.google.com/drive/android/auth#connecting_and_authorizing_the_google_drive_android_api