I am trying to retrieve the database file from the phone. I am using the cmd and adb shell to do this. After access data/data when i do ls, it shows permission denied. I have phone my rooted. USB debugging is on. My CMD image is attached. Please guide where i am wrong. Thanks in advance
Asked
Active
Viewed 1,985 times
0
-
You just run `su` to get root access from the shell. – OneCricketeer Jul 31 '16 at 19:51
-
Thanks you for you command. it works to access the files but now i cannot copy and paste the database file to my computer. – Mudasir Sharif Aug 01 '16 at 17:17
-
You can't "send" files from within ADB, you have to `pull` them – OneCricketeer Aug 01 '16 at 17:23
-
Yeahh I am doing the same.. like first I write cp databasename /sdcard/ and then pull databasename /sdcard/... I dont know if my commands are wrong but I am doing sam way.. – Mudasir Sharif Aug 01 '16 at 17:43
-
It is not really clear why you need to copy out the database. You can use a tool like [Stetho](https://facebook.github.io/stetho/) to inspect it – OneCricketeer Aug 01 '16 at 17:45
-
Now I dont want to spend time on a new tool to handle the database.. I just want it through adb shell. – Mudasir Sharif Aug 02 '16 at 08:43
-
Possible duplicate of [android adb, retrieve database using run-as](http://stackoverflow.com/questions/18471780/android-adb-retrieve-database-using-run-as) – Alex P. Sep 15 '16 at 15:26
1 Answers
3
To list all databases that you have:
adb shell run-as com.example.myapp ls /data/data/com.example.myapp/databases/
To download them, first, copy them to sdcard and then, pull it:
adb shell run-as com.example.myapp cp /data/data/com.example.myapp/databases/DATABASE_NAME /sdcard/
adb pull /sdcard/DATABASE_NAME
NOTE:
Remember to replace com.example.myapp
by package name from your app.
Replace com.example.myapp
by package marked in your AndroidManifest.xml
<manifest
package="com.example.myapp"/>
....
</manifest>

guipivoto
- 18,327
- 9
- 60
- 75
-
-
i ran the following commands adb devices and then adb shell run-as com.example.mudasir.login and then ls -1 /data/data/com.example.mudasir.login/databases – Mudasir Sharif Jul 31 '16 at 19:00
-
My Manifest file shows this package name. package="com.example.mudasir.login" – Mudasir Sharif Jul 31 '16 at 19:22
-
-
App is installed on the device up and running. I also wonder why its showing unknow. Is it related to the permission denied..?? – Mudasir Sharif Jul 31 '16 at 19:37
-
Run this command "adb shell pm list packages" Check if you can find any app with name *mudasir* – guipivoto Jul 31 '16 at 19:44
-
Another point... right command is ( ls -l ) and not ( ls -1 ).. to avoid confusion, remove -l parameter.. run only ls /data/data/com.example.mudasir.login/databases – guipivoto Jul 31 '16 at 19:48
-
su command works to access the internal files of the device and now i can approach to /data/data/com.exmaple.mudasir.login/databases. And if i do ls, i can see my database file. But i issue is i cannot copy and pull the file from device to my computer. – Mudasir Sharif Aug 01 '16 at 17:15
-
I was wondering my device don't have any sdcard. Is it considering the internal storage of device as sdcard..? I try to use your given commands but its showing no result. :( – Mudasir Sharif Aug 01 '16 at 17:16
-
I spend last 2.5 hours on figuring out this problem. After spending the hours when i put my hands up and by chance i saw my internal storage folder, i saw one database file which was my database. I succeeded randomly and i don't know which solution make it happen. Now again stuck because I don't know which solution worked, – Mudasir Sharif Aug 01 '16 at 19:55
-
Please figure out for me because it got stuck into my mind. I know i am doing a little syntax mistake. And in the last it will make me feel like fool..:( – Mudasir Sharif Aug 01 '16 at 19:56
-