unable to query the files "shared with me" from google drive using Google drive api android

987 Views Asked by At
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());
           }
        };
 }

I am not able to query the files and folders that already shared with me by using the above code. Whenever i am trying to query sharedWithMe() i am getting the mResultAdapter array count '0'. please help me to solve this issue.

2

There are 2 best solutions below

1
On

The Android API uses Drive.File scope, which means your app has access to files that have been created by, or explicitly opened with your app. Other files will not show up in search results.

0
On

Cheryl is right, you have to use Google APIs Java Client as said also here:

Note: The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes. If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client.

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