Search code examples
androidgoogle-drive-apigoogle-drive-android-api

Create file/folder in AN EXISTING drive folder


i have some troubles to understand all the Google Drive Api for Android.

I just wanna know, is that possible to create file/folder via an android application in AN EXISTING folder that has been created manually.

I've seen a lot of things that the GDAA doesnt allow to see/create/interact with files/folders not created by the device/application cause of the file.scope or app_folder.scope is that right ?

How could i manage to do that if not using the GDAA ? All others methods seems deprecated and i really need this functionnality.

Thanks a lot and sorry if some mistakes, not fluent.


Solution

  • As discussed in Working with Folders, you can:

    • Create a folder in the root folder

      Call DriveFolder.createFolder for the root folder. 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.

    • Create a folder inside a folder

      Any folder can be used to create a folder inside it. First, retrieve the folder from its DriveId, then call DriveFolder.createFolder. For a full working example, see the CreateFolderInFolderActivity sample.

    • Create file inside a folder

      Folders can also create files inside them using DriveFolder.createFile. This process is similar to creating files in the root folder. You should pass the metadata and contents for the file to the create method. For a full working example, see the CreateFileInFolderActivity sample.

    To answer your question regarding scope, to use Drive, you need to enable the API and at least one scope of SCOPE_FILE or SCOPE_APPFOLDER in a GoogleApiClient. Additionally, it was noted in Connecting and Authorizing the Google Drive Android API that:

    The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes. If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client.

    Lastly, for functionalities or features that are not available in Google Drive Android API, you may opt to use Google Drive REST API to Work with Folders.

    You can also refer to this SO post - Creating a folder inside a folder in google drive android. I hope that helps.