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:03

To backup from Android to Desktop

Open command line cmd and run this: adb backup -f C:\Intel\xxx.ab -noapk your.app.package. Do not enter password and click on Backup my data. Make sure not to save on drive C root. You may be denied. This is why I saved on C:\Intel.

To extract the *.ab file

  1. Go here and download: https://sourceforge.net/projects/adbextractor/
  2. Extract the downloaded file and navigate to folder where you extracted.
  3. run this with your own file names: java -jar abe.jar unpack c:\Intel\xxx.ab c:\Intel\xxx.tar
查看更多
旧人旧事旧时光
3楼-- · 2018-12-31 20:03

You can download a sigle file like that:

adb exec-out run-as debuggable.app.package.name cat files/file.mp4 > file.mp4

Before you download you might wan't to have a look at the file structure in your App-Directory. For this do the following steps THelper notice above:

adb shell
run-as com.your.packagename 
cd files
ls -als .

The Android-Studio way Shahidul mention (https://stackoverflow.com/a/44089388/1256697) also work. For those who don't see the DeviceFile Explorer Option in the Menu: Be sure, to open the /android-Directory in Android Studio. E.g. react-native users have this inside of their Project-Folder right on the same Level as the /ios-Directory.

查看更多
残风、尘缘若梦
4楼-- · 2018-12-31 20:04

may be to access this folder you need administrative rights.

so you have two options:-

  1. root your device and than try to access this folder
  2. use emulator

p.s. : if you are using any of above two options you can access this folder by following these steps

open DDMS perspective -> your device ->(Select File Explorer from right window options) select package -> data -> data -> package name ->files

and from there you can pull up your file

查看更多
弹指情弦暗扣
5楼-- · 2018-12-31 20:05

The easiest way (just one simple step) to pull a file from your debuggable application folder (let's say /data/data/package.name/databases/file) on an unrooted Android 5.0+ device is by using this command:

adb exec-out run-as package.name cat databases/file > file
查看更多
路过你的时光
6楼-- · 2018-12-31 20:05

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.

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

On a rooted device, the correct solution is this:

Open cmd
Change your directory and go into 'Platform tools'
Type 'adb shell'
su
Press 'Allow' on device
chmod 777 /data /data/data /data/data/*
Open DDMS view in Eclipse/IntelliJ and from there open 'FileExplorer' to get your desired file

The original solution worked, but the chmod would return unknown directory. Changing the chmod command to /data/data/* gave access to all subfolders in the data directory from DDMS in Intellij. I assume the same solution is true for Eclipse DDMS.

UPDATE So, what I've found is strange. I'm running a Nexus 6 using DDMS in IntelliJ (Android Device Monitor). I have built a little starter app. Said app saves data to a .csv file in data/data/com.example.myapp/files

When I first started to try to access this file on my Nexus 6, I found that I have to root the device.. I could see the data folder, but trying to open it would not work. As mentioned online in other places, the expand + would vanish then reappear shortly thereafter (note, there are solutions on the web that claim to allow access to these folders without rooting, I didn't find them till too late, and I'm not sure if I prefer not to root anyway ((I'd rather be able to do it manually than rely on an app or command prompt to give me my solutions))). I rooted my 6 and tried DDMS again.

At this point, it showed me the data folder and I could expand the folder and see the com. directories, but I could not open any of them. That is when I discovered the above solution. The initial instructions would not work on this part:

chmod 777 /data /data/data /data/data/com.application.pacakage /data/data/com.application.pacakage/*

That is when I tried the solution I posted:

chmod 777 /data /data/data /data/data/*

That solution seemed to work, but only on certain folders. I now could expand my myapp folder, but could not expand the files directory in it.

At this point, I played around for a while then figured why not just try it on the directory I need rather than trying these wildcard entries.

chmod 777 /data /data/data /data/data/com.example.myapp/*

Followed by:

chmod 777 /data /data/data /data/data/com.example.myapp/files

These commands allowed me to expand and view the files in my app's directory to confirm that the .csv was being saved correctly.

Hope this helps someone. I struggled with this for hours!

(to compound on this a tad further, oddly enough, the permissions did not pass to the .csv file that passed to the files directory. my files directory permissions read drwxrwxrwx and my log.csv file permissions read -rw-rw---- .. just fyi)

查看更多
登录 后发表回答