0
我試圖以編程方式將現有的.vcf
文件上傳到Google Drive。到目前爲止它只保存一個空文件。使用Google Drive API上傳文件
這可能很簡單,但我不熟悉Google Drive Api。 下面是代碼:
// Perform I/O off the UI thread.
new Thread() {
@Override
public void run() {
// write content to DriveContents
File f = new File("גיבוי אנשי קשר" + ".vcf");
filepath = f.getAbsolutePath().toString();
//String inFileName = Environment.getExternalStorageDirectory().getPath() + "גיבוי אנשי קשר" + ".vcf" ;
String inFileName = filepath;
File backupFile = new File(inFileName);
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(backupFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
byte[] buffer = new byte[8 * 1024];
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(driveContents.getOutputStream());
int n = 0;
try {
while ((n = bufferedInputStream.read(buffer)) > 0) {
bufferedOutputStream.write(buffer, 0, n);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
bufferedInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
//final MimeTypeMap mime = MimeTypeMap.getSingleton();
// String tmptype = mime.getMimeTypeFromExtension("vcf");
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("גיבוי אנשי קשר")
.setMimeType("text/x-vcard")
.setStarred(true).build();
這個例子是不相關的我也跟着在GitHub上的谷歌API的例子,這是什麼跟了上來。你能用我的代碼想到任何解決方案嗎? –