問題描述
我一直在嘗試將純文本文件保存到 Android 版 Google 云端硬盤中的特定文件夾中.
I've been trying to save a plain text file into a specific folder in Google Drive on Android.
到目前為止,我已經(jīng)能夠在 Google 云端硬盤上使用文檔和 快速入門指南做一些朝著正確方向發(fā)展的事情,首先我能夠創(chuàng)建一個純文本文件:
So far using the Documentation and QuickStart Guide on Google Drive I have been able to do a few things that are going in the right direction, first I was able to create a plain text file:
File body = new File();
body.setTitle(fileContent.getName());
body.setMimeType("text/plain");
File file = service.files().insert(body, textContent).execute();
我已經(jīng)能夠在 Google Drive 的基本目錄中創(chuàng)建一個新文件夾:
I have been able to create a new folder in the base directory of Google Drive with:
File body = new File();
body.setTitle("Air Note");
body.setMimeType("application/vnd.google-apps.folder");
File file = service.files().insert(body).execute();
我還能夠列出用戶 Google Drive 帳戶中的所有文件夾:
I have also been able to list all of the folders in the user's Google Drive account with:
List<File> files = service.files().list().setQ("mimeType = 'application/vnd.google-apps.folder'").execute().getItems();
for (File f : files) {
System.out.println(f.getTitle() + ", " + f.getMimeType());
}
但是,我對如何將文本文件保存到 Google Drive 中的文件夾中有點卡住.
However I am a bit stuck on how to save a text file into a folder within Google Drive.
推薦答案
你需要使用 parent 參數(shù)通過 insert 將文件放入文件夾中.https://developers.google.com/drive/v2/reference/了解更多詳情文件/插入
You need to use the parent parameter to put a file in a folder using insert. More details at https://developers.google.com/drive/v2/reference/files/insert
類似的東西
File body = new File();
body.setTitle(fileContent.getName());
body.setMimeType("text/plain");
body.setParents(Arrays.asList(new File.ParentReference().setId(parentId));
File file = service.files().insert(body, textContent).execute();
這篇關(guān)于使用 Google Drive SDK 將文件保存在特定文件夾中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!