54

I am testing an Android application.
I would like to keep an eye on the content of

/sdcard/Android/data/com.myapplication   

while the app is running.
But my app does not work correctly if the sd card is mounted as disk drive on PC (accesses pictures and videos).
So I thought I could use adb shell. But it doesn't let me access that same folder:

ls /sdcard/Android/data/com.myapplication  
/sdcard/Android/data/com.myapplication: Permission denied

Looking on Stack Overflow, I found this way to see application data via adb shell:

run-as com.myapplication

and doing so I find myself in the folder

/data/data/com.myapplication

What I'm confused about is that the data I see here are different from the data I see browsing the sdcard content via PC.

$ ls
ls
files
databases
shared_prefs
lib

I see under files something that was also under the sdcard Android/data/com.myapplication folder, but not what I was looking for. Besides, all other folders are different.
Is there a correlation between this

/data/data/com.myapplication

folder accessible via adb and the

/sdcard/Android/data/com.myapplication 

folder accessible via PC?
Is there a way to see in adb shell the files present in the latter?

Ele
  • 711
  • 2
  • 6
  • 7

3 Answers3

112

As a general rule, files that are on the Internal storage and stored by your app (by default not WORLD_READABLE) will only be available for your application to read. When you try to pull these files using adb pull you will get permission denied on a NOT rooted device. There is a way to go around this, I will explain later. Files in External storage on the other hand, are available to the User and to all other apps to read. so it depends on what you are after.

Now in order to read files in your internal storage (/data/data/com.app.name) you cannot read these files directly, but what you can do is move them to the external storage and then read them from there like this.

adb shell "run-as com.yourappName cat /data/data/com.yourappName/files/myfile.txt > /sdcard/Downloads/myfile.txt"

Then you can pull the file from the external storage with no permission issues.

adb pull /sdcard/Downloads/myfile.txt

If you are unsure about which file or you want to browse all the files, then user the shell to browse all your app files.

adb shell
run-as yourappPackageName
cd /data/data/youappPackageName
ls -all
Has AlTaiar
  • 4,052
  • 2
  • 36
  • 37
  • 6
    it shows "Permission denied" error. sh: can't create /sdcard/Download/syncadapter.txt: Permission denied – John Apr 15 '15 at 09:12
  • 1
    You may need to have your device rooted: https://www.kingoapp.com/root-tutorials/how-to-root-android.htm http://android.stackexchange.com/questions/127825/adb-shell-su-not-found – Testing Singh Mar 02 '16 at 18:51
  • on Samsung S7 Edge giving error: run-as: Could not set capabilities: Operation not permitted – Serdar Samancıoğlu Jun 14 '17 at 07:17
  • run-as command gives me the following error. run-as: Couldn't set capabilities: Operation not permitted. – Andrew Li Jul 13 '18 at 07:05
  • It seems that if the app you run-as does not have storage write permissions, this wont work. It also seems that for unrooted devices and apps without writing permission, there is no folder where app can write and adb can pull. – Lukas Hanacek Oct 22 '19 at 12:01
  • 3
    No need to create an intermediate file on `/sdcard` — just `cat` the original and redirect the output of `adb` to a local file. – Ruslan Nov 20 '19 at 06:50
  • 23
    This works only with debuggable apps. Might be worth mentioning that in the answer. – Timo Jun 06 '20 at 10:18
  • Also to add to @Ruslan comment, while the sdcard trick is rather useless if your pulling only a single file, it is convenient if you want to pull an entire folder. Something like `adb shell "run-as com.yourappName cp -R /data/data/com.yourappName/files /sdcard/com.yourappName_files" && adb pull /sdcard/com.yourappName_files && adb shell rm -Rf /sdcard/com.yourappName_files` – Timo Jun 06 '20 at 13:50
  • 1
    @Timo even in the case of multiple files you don't need an intermediate storage. Just do `adb shell 'run-as com.yourappName tar cf - /data/data/com.yourappName_files/' | tar xvf -` – Ruslan Jun 06 '20 at 14:40
  • Yeah, that's actually the better approach on unix. Not sure if you can do that with Windows? – Timo Jun 06 '20 at 16:05
  • to add an exampleto @Rusians version (which was the only one working on my devices): 'adb shell "run-as de.url.yourapp cat /data/data/de.url.yourapp/files/filetoread.json" > Desktop/filecopy.json' works great – gaugau Jun 19 '20 at 22:34
9

I have been able to get the Sqlite DB the App is using with this Adb command:

adb exec-out run-as xxx.xxx.xxx.xxx cat "/data/data/xxx.xxx.xxx.xxx/databases/databasefile.db" > %userprofile%\Desktop\databasefile.db

Where xxx.xxx.xxx.xxx is the bundleId of your Android App, and databasefile.db is the name of the Sqlite DB

So I imagine you can get any existing file of the App, knowing where is it, and using the adb exec-out run-as xxx.xxx.xxx.xxx command

rtrujillor
  • 1,162
  • 1
  • 12
  • 23
  • 1
    you may use relative path here .. in your example it would be databases/databasefile.db . thank you – ish1313 May 07 '21 at 10:46
-1

You can access it via utility which was posted earlier in a blog. Its a java utility through which you can get the all folders in your application's data folder by just giving the package name of your application. Just app needs to be debuggable.

Extract Android Files

Really works

Community
  • 1
  • 1
Mohammed Rampurawala
  • 3,033
  • 2
  • 22
  • 32