我想将我的应用程序数据库上传到谷歌驱动器。
我已经尝试了几次,但不幸的是每次都失败了。这是给我带来大量失败的代码。
请告诉我一条适当的路径来解决这个问题。任何人的帮助都将受到高度赞赏。
OutputStream outputStream = driveContents.getOutputStream();
InputStream is = null;
try {
byte[] buf = new byte[4096];
is = new FileInputStream(dbPath);
int c;
while ((c = is.read(buf, 0, buf.length)) > 0)
outputStream.write(buf, 0, c);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
outputStream.flush(); outputStream.close();
if (is != null )is.close();
} catch (Exception e) {e.printStackTrace();}
}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("Viki")
.setMimeType("application/x-sqlite3")
.setStarred(true).build();
// create a file in root folder
Drive.DriveApi.getRootFolder(mGoogleApiClient)
.createFile(mGoogleApiClient, changeSet, driveContents)
.setResultCallback(fileCallback);