这可能是一个愚蠢的问题,但我找不到任何解决方案。我需要知道如何备份roomdatabase并使用Google Drive检索它。那么房间数据库的mime类型是什么?任何人都可以知道如何做到这一点?让我发布到目前为止我所尝试的内容:
private void saveFileToDrive(File file) {
mDriveClient = Drive.getDriveClient(this, GoogleSignIn.getLastSignedInAccount(this));
// Build a drive resource client.
mDriveResourceClient =
Drive.getDriveResourceClient(this, GoogleSignIn.getLastSignedInAccount(this));
final Task<DriveFolder> rootFolderTask =mDriveResourceClient.getRootFolder();
final Task<DriveContents> createContentsTask =mDriveResourceClient.createContents();
Tasks.whenAll(rootFolderTask, createContentsTask)
.continueWithTask(new Continuation<Void, Task<DriveFile>>() {
@Override
public Task<DriveFile> then(@NonNull Task<Void> task) throws Exception {
DriveFolder parent = rootFolderTask.getResult();
DriveContents contents = createContentsTask.getResult();
// OutputStream outputStream = contents.getOutputStream();
// try (Writer writer = new OutputStreamWriter(outputStream)) {
// writer.write("Hello World!");
// }
OutputStream oos = contents.getOutputStream();
if (oos != null) try {
InputStream is = new FileInputStream(file);
byte[] buf = new byte[4096];
int c;
while ((c = is.read(buf, 0, buf.length)) > 0) {
oos.write(buf, 0, c);
oos.flush();
}
}
finally { oos.close();}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("mm.db")
.setMimeType("application/x-sqlite3")
.setStarred(true)
.build();
return mDriveResourceClient.createFile(parent, changeSet, contents);
}
})
.addOnSuccessListener(this,
new OnSuccessListener<DriveFile>() {
@Override
public void onSuccess(DriveFile driveFile) {
// showMessage(getString(R.string.file_created,
// driveFile.getDriveId().encodeToString()));
finish();
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Unable to create file", e);
// showMessage(getString(R.string.file_create_error));
finish();
}
});
}
如何备份频繁的时间但使用房间数据库android?提前谢谢。