Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a folder inside a folder in google drive android

I want to integrate Google drive with my app I have registered my app in Google Developers Console. I got a sample from https://github.com/googledrive/android-demos .By this i am able to create a file,folder in Google drive's root folder but the problem is I couldn't create a file or folder inside an existing folder. In such case i got a toast "Cannot find DriveId. Are you authorized to view this file?" ie I cannot get the driveID

public class CreateFolderInFolderActivity extends BaseDemoActivity {

@Override
public void onConnected(Bundle connectionHint) {
    super.onConnected(connectionHint);
    Drive.DriveApi.fetchDriveId(getGoogleApiClient(), EXISTING_FOLDER_ID)
            .setResultCallback(idCallback);
}

final ResultCallback<DriveIdResult> idCallback = new ResultCallback<DriveIdResult>() {
    @Override
    public void onResult(DriveIdResult result) {
        if (!result.getStatus().isSuccess()) {
             showMessage(result.getStatus().toString());
            showMessage("Cannot find DriveId. Are you authorized to view this file?");
            return;
        }
        DriveFolder folder = Drive.DriveApi
                .getFolder(getGoogleApiClient(), result.getDriveId());
        MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                .setTitle("MyNewFolder").build();
        folder.createFolder(getGoogleApiClient(), changeSet)
                .setResultCallback(createFolderCallback);
    }
};

final ResultCallback<DriveFolderResult> createFolderCallback = new
        ResultCallback<DriveFolderResult>() {

    @Override
    public void onResult(DriveFolderResult result) {
        if (!result.getStatus().isSuccess()) {
            showMessage("Problem while trying to create a folder");
            return;
        }
        showMessage("Folder successfully created");
    }
};
}

I cannot find any proper documentation for this. Plz help me where i am going wrong or Whether I Have to include any other permissions

like image 534
Dhiliph Soundher Avatar asked Mar 03 '14 06:03

Dhiliph Soundher


1 Answers

You can take a peek here: in the 'createTree()' method, there is a creation of folder within a folder.

There are 3 different drive ID entities in the new Google Drive Android API (GDAA)

  1. the object of type DriveID - the one you get from methods and use in your code
  2. a string you get from encodeToString() and pass to decodeFromString() - used to save within the app (caching for instance)
  3. a string you get from getResourceId() and pass to fetchDriveId() - the one you see in the html address of a file.

Both 2 and 3 identifiers are strings, so they may be confused. Identifier 2 is faster when retrieving Drive ID (via decodeFromString()). Identifier 3 is slower to retrieve (via fetchDriveId()), but usefull if you need to take your ID elsewhere (Apps Script, for instance).

Please see also: SO 21800257

like image 112
seanpj Avatar answered Oct 20 '22 17:10

seanpj