Filters.ownedByMe does not work in the "Drive API for Android" (but works correctly in the "Client API library for Java")

I used to use the Client API Library for Java to search for files in the appdata folder.

File Search Code in the Java API Client Library

private static void searchFromGoogleDrive(Drive drive, String qString) { try { Files.List request = drive.files().list().setQ(qString); do { FileList fileList = request.execute(); for (com.google.api.services.drive.model.File f : fileList.getItems()) { final String title = f.getTitle(); if (title == null || f.getDownloadUrl() == null || f.getDownloadUrl().length() <= 0) { continue; } ... } request.setPageToken(fileList.getNextPageToken()); } while (request.getPageToken() != null && request.getPageToken().length() > 0); } catch (IOException ex) { log.error(null, ex); return; } return; } 

It works great for the next query line.

 title contains 'jstock-fe78440e-e0fe-4efb' and trashed = false and 'appdata' in parents and 'me' in owners 

Recently, I am trying to port the code to use the "Drive API for Android". I have 2 areas for GoogleApiClient

  • Drive.SCOPE_FILE
  • Drive.SCOPE_APPFOLDER

File Search Code in the Android API Driver

 private static void searchFromGoogleDrive(GoogleApiClient googleApiClient) { DriveFolder driveFolder = Drive.DriveApi.getAppFolder(googleApiClient); Query query = new Query.Builder() .addFilter(Filters.and( Filters.contains(SearchableField.TITLE, "jstock-fe78440e-e0fe-4efb"), Filters.eq(SearchableField.TRASHED, false), Filters.ownedByMe() )) .build(); DriveApi.MetadataBufferResult metadataBufferResult = driveFolder.queryChildren(googleApiClient, query).await(); if (metadataBufferResult == null) { Log.i("CHEOK", "metadataBufferResult is null"); } else { Log.i("CHEOK", "metadataBufferResult status = " + metadataBufferResult.getStatus().isSuccess()); } if (metadataBufferResult != null && metadataBufferResult.getStatus().isSuccess()) { MetadataBuffer metadataBuffer = null; try { metadataBuffer = metadataBufferResult.getMetadataBuffer(); if (metadataBuffer != null ) { for (Metadata md : metadataBuffer) { if (md == null || !md.isDataValid()) { continue; } Log.i("CHEOK", "title = " + md.getTitle()); } // for } // if } finally { if (metadataBuffer != null) { metadataBuffer.release(); } } } return; } 

I understand Filters.ownedByMe is what causes the problem.

Here are different results based on different queries.

Mistake

 Query query = new Query.Builder() .addFilter(Filters.and( Filters.contains(SearchableField.TITLE, "jstock-fe78440e-e0fe-4efb"), Filters.eq(SearchableField.TRASHED, false), Filters.ownedByMe() )) .build(); // metadataBufferResult status = false 

Mistake

 Query query = new Query.Builder() .addFilter(Filters.and( Filters.ownedByMe() )) .build(); // metadataBufferResult status = false 

Success

 Query query = new Query.Builder() .addFilter(Filters.and( Filters.contains(SearchableField.TITLE, "jstock-fe78440e-e0fe-4efb"), Filters.eq(SearchableField.TRASHED, false) )) .build(); // metadataBufferResult status = true // title = jstock-fe78440e-e0fe-4efb-881d-264a01be483c-checksum=2298926779-date=1452429908167-version=1107.zip 

Filters.ownedByMe() doesn't seem to work correctly in Drive API for Android

Is there anything I can fix?

0
java android google-drive-sdk google-drive-android-api
Jan 10 '16 at 13:26
source share

No one has answered this question yet.

See similar questions:

54
Avoid downloading cached app data from Google Drive
7
Google Drive API - the name must not be empty: null (But I passed the valid account name to GoogleAccountCredential)
7
Invalid parent folder error for AppFolder in API driver

or similar:

1249
How does the Java loop work for each loop?
1116
Installing Android SDK does not find JDK
947
Android Studio: add jar as a library?
911
Getting current working directory in Java
784
How to add a library project in Android Studio?
666
Android getResources (). GetDrawable () deprecated API 22
578
Can I use Java 8 for Android development?
four
Are files created using a Google Drive account when authenticating with a service account?
2
Android, the Google Drive API. Folder search / insert java.lang.IllegalArgumentException: cannot create new instance of class com.google.abaae
one
Android Drive API V3 - How do I know if a file has been damaged or deleted?



All Articles