我怎么能拉过我的Andr​​oid数据库到我的桌面?我的、拉过、桌面、数据库

2023-09-05 07:31:52 作者:姑娘对自己好才是王道

我想这与我的Nexus One。 我有Android SDK和已使用的命令 亚行拉/data/data/com.myapp.android/databases C:\拉 但我得到的是 拉:建立文件列表... 0文件拉升。 0文件跳过。 此外,它似乎不管有多少数据我添加到教程记事本应用程序,我安装的应用程序中的数据的大小(如设置所示)不超过8KB。这怎么可能?是否存在这样的数据库存储一些其他的地方?当我使用File Explorer视图(这是ADT的一部分)在Eclipse中,我看到有什么在/数据。 要添加一拧,我没有问题,从设备拉动的其他文件。这只是数据库我有麻烦了。 我失去了一些东西?谢谢了。

I'm trying this with my Nexus One. I have the android SDK and have used the command adb pull /data/data/com.myapp.android/databases C:\pulls but all I get is pull: building file list... 0 files pulled. 0 files skipped. Also, it seems no matter how much data I add to the tutorial NotePad app I installed, the data size for the app (as shown in Settings) never exceeds 8KB. How is this possible? Is there some other place where databases are stored? When I use the File Explorer view (that's part of ADT) in Eclipse, I see there's nothing in /data. To add a twist, I have no trouble pulling any other files from the device. It's just databases I have trouble with. Am I missing something? Thanks much.

推荐答案

访问内部存储是不可能的,除非你的手机是植根。一个简单的方法是使用模拟器,然后你就可以在文件获取。为了得到一个数据库关闭设备我写了一个小工具,并把一些调试UI吧:

Accessing internal storage is not possible unless your phone is rooted. One simple way is to use the emulator, and then you can get at the files. For getting a database off the device I wrote a little utility and put in some debug UI for it:

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();
    }
}