How to access data/data folder in Android device?

后端 未结 18 2181
南方客
南方客 2020-11-22 15:36

I am developing an app and I know my database *.db will appear in data/data/com.****.***

I can access this file from AVD in Eclipse with he

18条回答
  •  孤街浪徒
    2020-11-22 16:17

    I had also the same problem once. There is no way to access directly the file within android devices except adb shell or rooting device.

    Beside here are 02 alternatives:

    1)

     public void exportDatabse(String databaseName)
       {
         try {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();
    
            if (sd.canWrite()) {
                String currentDBPath = "//data//"+getPackageName()+"//databases//"+databaseName+"";
                String backupDBPath = "backupname.db";
                File currentDB = new File(data, currentDBPath);
                File backupDB = new File(sd, backupDBPath);
    
                if (currentDB.exists()) {
                    FileChannel src = new FileInputStream(currentDB).getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                }
            }
        } catch (Exception e) {
    
        }
    }
    

    2) Try this: https://github.com/sanathp/DatabaseManager_For_Android

提交回复
热议问题