SimpleCoder
SimpleCoder

Reputation: 1705

Create folder in drive with rest v2 in android app

I am trying to create a folder in Drive and using below

 String folderName = UrlConstants.APP_NAME + "_dont_delete";
    File fileMetadata = new File();
    fileMetadata.setTitle(folderName);
    fileMetadata.setMimeType("application/vnd.google-apps.folder");

    File file = null;
    try {
        file = driveService.files().insert(fileMetadata)
                .setFields("id")
                .execute();
    } catch (IOException e) {
        e.printStackTrace();
    }

However it is not creating folder in drive , instead it is creating a document named 'Untitled'.

Thanks in advance.

Upvotes: 0

Views: 153

Answers (2)

Tmm
Tmm

Reputation: 187

The CloudRail SDK allows you to do that in a pretty simple way:

GoogleDrive service = new GoogleDrive(
    this,
    "[Google Drive Client Identifier]",
    "[Google Drive Client Secret]",
    "http://localhost:12345/auth",
    "someState"
);

service.createFolder(
    "/myFolder"
);

Upvotes: 1

Prateekro
Prateekro

Reputation: 566

In Drive API for Android, note that working with folders has slight differences when compared to Google Drive API. Folders in the Drive API for Android are specialized resources within metadata and a DriveId and to create a folder, call DriveFolder.createFolder for the root folder. Then, pass the metadata containing the title and other attributes to set the values for the folder.

For a full working example, see the CreateFolderActivity sample in the Google Drive Android API Demos app.

Upvotes: 1

Related Questions