1

In my Andorid app, I want to access only those file which is shared with me either by web(drive.google.com) or app. I am using google drive API to access shared file but I am not able to access any file or folder shared with me. My code is given below.

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());
            }
        };

}

Note* Can we filter a file or folder shared with me with a specific folder name?

Termininja
  • 6,620
  • 12
  • 48
  • 49
Sirconrad
  • 69
  • 1
  • 3
  • 7
  • You say "i am not able to access any file or folder shared with me ". Do you mean GoogleDrive folders and files that are owned by others but shared with you? – Bob Snyder Jun 28 '15 at 00:22
  • @qbix yes, i want to access google drive folder and files that are owned by other but shared with me. – Sirconrad Jun 28 '15 at 09:29
  • The answer to [this related issue](http://stackoverflow.com/questions/26929154/unable-to-get-the-shared-with-me-files-with-the-google-drive-api-using-filters-s?lq=1) indicates that the Android GoogleDrive API does not support access to shared files, even though the query options exist. When you run your query, do you get any results? – Bob Snyder Jun 28 '15 at 15:48

1 Answers1

0

Is your app authorized to access the shared files? Currently Google Drive Android API only supports FILE scope access (see details here). So if your app is not authorized to access those shared files, you won't receive them in the query result.

Shailendra
  • 213
  • 3
  • 9
  • hello Shailendra,My file is already authorized to access file. Currently it is accessing only those file created by my application. I want to access those file which is create from web. can you please add me on skype sachin.auxiliumit. I will be very thankful of you. I am struggling from last 7 days. – Sirconrad Jun 28 '15 at 07:23
  • If a Drive file is created on web, user must specifically authorize a FILE scoped app on the Drive file so that the app can access it. What's the underlying reason to access the shared file? If you want to perform actions on an individual file you can request for the [open file activity](https://developers.google.com/android/reference/com/google/android/gms/drive/OpenFileActivityBuilder) where the user can choose a Drive file (can be a shared file) and your app gets the DriveId of the selected file to perform any actions on it. – Shailendra Jun 29 '15 at 03:23