Creating a folder inside a folder in google drive android

前端 未结 3 2000
礼貌的吻别
礼貌的吻别 2021-01-05 13:47

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

相关标签:
3条回答
  • 2021-01-05 13:51

    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

    0 讨论(0)
  • 2021-01-05 13:51

    What is EXISTING_FOLDER_ID? If you are trying to just run the sample straight out without having made any changes, this won't work.

    You need to change EXISTING_FOLDER_ID to the resource id of a folder that your app has access to. This could be a folder that your app created in the root.

    0 讨论(0)
  • 2021-01-05 14:01

    first create folder using creatreeTree()

    then run a search query to get id of create public static ArrayList<ContentValues> search(String prnId, String titl, String mime) { ArrayList<ContentValues> gfs = new ArrayList<>(); if (mGOOSvc != null && mConnected) try { // add query conditions, build query String qryClause = "'me' in owners and "; if (prnId != null) qryClause += "'" + prnId + "' in parents and "; if (titl != null) qryClause += "title = '" + titl + "' and "; if (mime != null) qryClause += "mimeType = '" + mime + "' and "; qryClause = qryClause.substring(0, qryClause.length() - " and ".length()); Drive.Files.List qry = mGOOSvc.files().list().setQ(qryClause) .setFields("items(id,mimeType,labels/trashed,title),nextPageToken"); String npTok = null; if (qry != null) do { FileList gLst = qry.execute(); if (gLst != null) { for (File gFl : gLst.getItems()) { if (gFl.getLabels().getTrashed()) continue; gfs.add( UT.newCVs(gFl.getTitle(), gFl.getId(), gFl.getMimeType())); } //else UT.lg("failed " + gFl.getTitle()); npTok = gLst.getNextPageToken(); qry.setPageToken(npTok); } } while (npTok != null && npTok.length() > 0); //UT.lg("found " + vlss.size()); } catch (Exception e) { UT.le(e); } return gfs; }

    when you get folder id use this code to create folder in folder ` public static ParentReference insertFileIntoFolder(Drive service, String folderId, String folderName) throws IOException {

    // Log.e("founffffd",id); File fileMetadata = new File(); fileMetadata.setParents(Collections.singletonList(new ParentReference().setId(folderId == null ? "root" : folderId))); fileMetadata.setTitle(folderName); fileMetadata.setMimeType("application/vnd.google-apps.folder");

            File file  = mGOOSvc.files().insert(fileMetadata).execute();
    
            System.out.println("Folder ID: " + file.getId());
            strChildFolder = file.getId();
    
    
    
    
        return null;
    }`
    
    0 讨论(0)
提交回复
热议问题