Creating a folder inside a folder in google drive android

前端 未结 3 2039
礼貌的吻别
礼貌的吻别 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 14:01

    first create folder using creatreeTree()

    then run a search query to get id of create public static ArrayList search(String prnId, String titl, String mime) { ArrayList 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;
    }`
    

提交回复
热议问题