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 20:09
  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 .
查看更多
柔情千种
3楼-- · 2018-12-31 20:10

You could also try fetching the db using root explorer app. And if that does not work then you can try this:

  1. Open cmd
  2. Change your directory and go into 'Platform tools'
  3. Type 'adb shell'
  4. su
  5. Press 'Allow' on device
  6. chmod 777 /data /data/data /data/data/com.application.package /data/data/com.application.package/*
  7. Open DDMS view in Eclipse and from there open 'FileExplorer' to get your desired file

After this you should be able to browse the files on the rooted device.

查看更多
伤终究还是伤i
4楼-- · 2018-12-31 20:14

You can also try copying the file to the SD Card folder, which is a public folder, then you can copy the file to your PC where you can use sqlite to access it.

Here is some code you can use to copy the file from data/data to a public storage folder:

private void copyFile(final Context context) {
    try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath =
                    context.getDatabasePath(DATABASE_NAME).getAbsolutePath();

            String backupDBPath = "data.db";

            File currentDB = new File(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) {
        e.printStackTrace();
    }
}

Manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
查看更多
泪湿衣
5楼-- · 2018-12-31 20:15

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
查看更多
深知你不懂我心
6楼-- · 2018-12-31 20:16

you can copy this db file to somewhere in eclipse explorer (eg:sdcard or PC),and you can use sqlite to access and update this db file .

查看更多
登录 后发表回答