Save file in specific folder with Google Drive SDK

后端 未结 3 1957
臣服心动
臣服心动 2020-12-16 06:27

I\'ve been trying to save a plain text file into a specific folder in Google Drive on Android.

So far using the Documentation and QuickStart Guide on Google Drive I

3条回答
  •  悲哀的现实
    2020-12-16 07:02

    If you want to INSERT a file in specific folder in Google Drive then follow these steps. Lets assume that we have retrieved all folder from the Drive and now i will INSERT an empty file in the first folder from the list, So

             //Getting Folders from the DRIVE
    List files = mService.files().list().setQ("mimeType = 'application/vnd.google-apps.folder'").execute().getItems();
    
       File f  =files.get(1)//getting first file from the folder list
        body.setTitle("MyEmptyFile");
        body.setMimeType("image/jpeg");
        body.setParents(Arrays.asList(new ParentReference().setId(f.getId())));
        com.google.api.services.drive.model.File file = mService.files().insert(body).execute();
    

    Now this will create an empty file in the Folder which are at the top in the retrieve file list.

提交回复
热议问题