0

I have just started android app creating about a week ago, I have written an application that can display images from a user's google drive account, however when I load the application it starts at root folder (by default). I need the app to open in a specific folder with the same name across multiple accounts.

For example regardless of the user I want the app to open in their "my pics" folder.

I understand the way to do this is to .setActivityStartFolder(folderID)

However, I don't know how to get the ID of a folder by name. Is there a way to Query and filter down to only folders with that specific name and then get the ID? thanks in advance,

Ross.

For reference here is my activity builder:

IntentSender intentSender = Drive.DriveApi
                .newOpenFileActivityBuilder()
                //setActivityStartFolder(folderID) NEEDS TO GO HERE?
                .setMimeType(new String[]{ "video/mp4", "image/jpeg" })
                .build(getGoogleApiClient());

1 Answers1

1

I find the answer here.

DriveFile file = Drive.DriveApi.getFile(mGoogleApiClient,
        DriveId.decodeFromString(driveIdStr));
file.open(mGoogleApiClient, DriveFile.MODE_WRITE_ONLY, null).setResultCallback(new ResultCallback<DriveContentsResult>() {
    @Override
    public void onResult(DriveContentsResult result) {
        if (!result.getStatus().isSuccess()) {
            // Handle error
            return;
        }
        DriveContents driveContents = result.getDriveContents();
    }
});

driveIdStr is something like this and you can find driveIDstring as described in this link.

private static DriveId sFolderId = DriveId.decodeFromString("DriveId:0B2EEtIjPUdX6MERsWlYxN3J6RU0");
Community
  • 1
  • 1
Mehran Zamani
  • 831
  • 9
  • 31
  • Unfortunately I believe getFile is no longer in use, as I recall trying that particular solution. – ross franey Feb 07 '17 at 08:34
  • This method was deprecated. Use `asDriveFolder()` instead. [this link](https://developers.google.com/android/reference/com/google/android/gms/drive/DriveApi.html#getFolder(com.google.android.gms.common.api.GoogleApiClient,com.google.android.gms.drive.DriveId)) – Mehran Zamani Apr 23 '17 at 07:19