【发布时间】:2015-11-09 05:01:42
【问题描述】:
我正在尝试将应用程序数据库备份和恢复到谷歌驱动器应用程序文件夹的功能(用户不可见)。我浏览了为 android 提供的基本设置指南 setup guide,可以让用户授权应用程序并到达调用 onConnected 方法的位置。
我面临的问题是,我不确定如何将数据库文件 (.db) 从设备“发送”到 google drive app 文件夹。 Google 已共享 sn-p 用于创建新文件,仅此而已。我确实发现了一个先前提出的问题,与我正在寻找的 Google drive to back up and restore database and shared preferences of Android application 模糊相似,但又不是我想要的。
搜索 google 不会返回任何有用的链接,可能是因为这是相对较新的 api。
更新 1:
分享 onConnected() 代码,
public void onConnected(Bundle bundle) {
Toast.makeText(GoogleSignIn.this, "In onConnected activity", Toast.LENGTH_SHORT).show();
// Testing to see if database is indeed uploaded to google drive app folder
String db_name = "XXX_DB";
String currentDBPath = "/data/" + "com.abc.efg" + "/databases/" + db_name;
saveToDrive(
Drive.DriveApi.getAppFolder(mGoogleApiClientDrive),
"XXX_DB.db",
"application/x-sqlite3",
new java.io.File(currentDBPath)
);
}
更新 2:
下面分享的解决方案非常适合将数据库上传到 google drive app 文件夹。对于那些可能面临类似问题的人,请尝试将数据库路径更改为 "/data/data/com.abc.efg/databases/" + db_name 而不是 "/data/com.abc.efg/databases/" + db_name
下一步是能够从 google drive app 文件夹中检索和恢复数据库。如果我能够让它工作,我会更新这个问题。
【问题讨论】:
标签: android android-sqlite google-drive-android-api