Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

android - is it possible to see application data from adb shell the same way I see it mounting SD card?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...