How to access data/data folder in Android device?

后端 未结 18 1877
南方客
南方客 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:14

    One of the simple way is to create your database on SD-Card. Because you cannot get access to your phone's data folder in internal memory, unless you root your phone. So why not simply create your database on SD-Card.

    Moreover, if you want, you may write some file copying-code to copy your existing database file (from internal memory) to external memory without requiring any root.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-11-22 16:19

    To do any of the above (i.e. access protected folders from within your phone itself), you still need root. (That includes changing mount-permissions on the /data folder and accessing it)

    Without root, accessing the /data directly to read except from within your application via code isn't possible. So you could try copying that file to sdcard or somewhere accessible, and then, you should be able to access it normally.

    Rooting won't void your warranty if you have a developer device. I'm sorry, there isn't any other way AFAIK.

    0 讨论(0)
  • 2020-11-22 16:19
    1. Open your command prompt
    2. Change directory to E:\Android\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk\platform-tools
    3. Enter below commands
    4. adb -d shell
    5. run-as com.your.packagename cat databases/database.db > /sdcard/database.db
    6. Change directory to cd /sdcard to make sure database.db is there.
    7. adb pull /sdcard/database.db or simply you can copy database.db from device .
    0 讨论(0)
  • 2020-11-22 16:20

    The question is: how-to-access-data-data-folder-in-android-device?


    If android-device is Bluestacks * Root Browser APK shows data/data/..


    Try to download Root Browser from https://apkpure.com/root-browser/com.jrummy.root.browserfree


    If the file is a text file you need to click on "Open as", "Text file", "Open as", "RB Text Editor"

    0 讨论(0)
  • 2020-11-22 16:23

    Use File Explorer in eclipse. Select Windows => Show View => Other ... => File Explorer.

    An another way is pull the file via adb:

    adb pull /system/data/data/<yourpackagename>/databases/<databasename> /sdcard
    
    0 讨论(0)
提交回复
热议问题