我正在用我的 Nexus One 尝试这个。 我有 android SDK 并使用了命令 adb pull/data/data/com.myapp.android/databases C:\pulls 但我得到的只是 拉:构建文件列表... 已提取 0 个文件。跳过 0 个文件。 此外,似乎无论我向安装的教程 NotePad 应用程序添加多少数据,该应用程序的数据大小(如“设置”中所示)都不会超过 8KB。这怎么可能?还有其他存储数据库的地方吗?当我在 Eclipse 中使用文件资源管理器 View (它是 ADT 的一部分)时,我发现/data 中没有任何内容。 更有趣的是,我可以毫不费力地从设备中提取任何其他文件。这只是我遇到麻烦的数据库。 我错过了什么吗?非常感谢。
最佳答案
除非您的手机已 root,否则无法访问内部存储。一种简单的方法是使用模拟器,然后您就可以获取文件。为了从设备上获取数据库,我编写了一个小实用程序并为其放入了一些调试 UI:
private void backupDb() throws IOException {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "/data/com.yourcompany.yourapp/databases/yourapp.db";
String backupDBPath = "/yourapp_logs/yourapp.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (backupDB.exists())
backupDB.delete();
if (currentDB.exists()) {
makeLogsFolder();
copy(currentDB, backupDB);
}
dbFilePath = backupDB.getAbsolutePath();
}
}
private void makeLogsFolder() {
try {
File sdFolder = new File(Environment.getExternalStorageDirectory(), "/yourapp_logs/");
sdFolder.mkdirs();
}
catch (Exception e) {}
}
private void copy(File from, File to) throws FileNotFoundException, IOException {
FileChannel src = null;
FileChannel dst = null;
try {
src = new FileInputStream(from).getChannel();
dst = new FileOutputStream(to).getChannel();
dst.transferFrom(src, 0, src.size());
}
finally {
if (src != null)
src.close();
if (dst != null)
dst.close();
}
}
关于android - 如何将数据库从我的 android 拉到我的桌面上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4202064/