How to access data/data folder in Android device?

2018-12-31 19:38发布

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 help of sqlite manager

But I can't access this file in my Android phone.
I google it and it says I need to root my phone to do it, but I don't want to do it. (New phone, warranty issues, and security issues)

So here is my question: How can I access my data/data/..... directory in my Android phone "without rooting it"?

Can I change user permissions for the directory data/data..... without rooting it?

17条回答
浪荡孟婆
2楼-- · 2018-12-31 19:53

adb backup didn't work for me, so here's what I did (Xiaomi Redmi Note 4X, Android 6.0):
1. Go to Settings > Additional Settings > Backup & reset > Local backups.
2. Tap 'Back up' on the bottom of the screen.
3. Uncheck 'System' and 'Apps' checkmarks.
4. Tap detail disclosure button on the right of the 'Apps' cell to navigate to app selection screen.
5. Select the desired app and tap OK.
6. After the backup was completed, the actual file need to be located somehow. Mine could be found at /MIUI/backup/AllBackup/_FOLDER_NAMED_AFTER_BACKUP_CREATION_DATE_.
7. Then I followed the steps from this answer by RonTLV to actually convert the backup file (.bak in my case) to tar (duplicating from the original answer):
"
a) Go here and download: https://sourceforge.net/projects/adbextractor/
b) Extract the downloaded file and navigate to folder where you extracted.
c) run this with your own file names: java -jar abe.jar unpack c:\Intel\xxx.ab c:\Intel\xxx.tar
"

查看更多
梦寄多情
3楼-- · 2018-12-31 19:54

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"

查看更多
刘海飞了
4楼-- · 2018-12-31 20:00

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.

查看更多
骚的不知所云
5楼-- · 2018-12-31 20:01

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

查看更多
柔情千种
6楼-- · 2018-12-31 20:02

Accessing the files directly on your phone is difficult, but you may be able to copy them to your computer where you can do anything you want with it. Without rooting you have 2 options:

  1. If the application is debuggable you can use the run-as command in adb shell

    adb shell
    run-as com.your.packagename 
    cp /data/data/com.your.packagename/
    
  2. Alternatively you can use Android's backup function.

    adb backup -noapk com.your.packagename
    

    You will now be prompted to 'unlock your device and confirm the backup operation'. It's best NOT to provide a password, otherwise it becomes more difficult to read the data. Just click on 'backup my data'. The resulting 'backup.ab' file on your computer contains all application data in android backup format. Basically it's a compressed tar file. This page explains how you can use OpenSSL's zlib command to uncompress it. You can use the adb restore backup.db command to restore the backup.

查看更多
荒废的爱情
7楼-- · 2018-12-31 20:02

If you are using Android Studio 3.0 or later version then follow these steps.

  1. Click View > Tool Windows > Device File Explorer.
  2. Expand /data/data/[package-name] nodes.

You can only expand packages which runs in debug mode on non-rooted device.

Steps followed in Android Studio 3.0

查看更多
登录 后发表回答