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的例子,这是什么跟了上来。你能用我的代码想到任何解决方案吗? –