android - 如何将数据库从我的 android 拉到我的桌面上?

标签 android database location pull nexus-one

我正在用我的 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/

相关文章:

android - 如何仅在 .pro 文件中为 Android 平台构建指定库?

android - 如何添加两个android :name attributes to Application tag in Manifest file?

ios - MapKit 没有以正确的位置为中心

java - 将 ScrollView 中的 TextView 滚动到特定的文本子串

android - 与 android 支持库的依赖关系不适用于使用 Androidx 的项目

database - 远程连接 Azure SQL Server 不显示所有数据库

database - 计算一组 FD 的闭包的算法

python - 递归关系和与 Django 中未定义模型的关系有什么用?

ios - 使用坐标列表在 Mapkit 上画一条线

iphone - 如何在 objective-c 中将gps north和gps west转换为lat/long