As a brief note, today I tried to list the files in my Android application, which was running on a physical Android device — a Nexus 9 — with this
adb shell command:
adb shell com.alvinalexander.mybrowser ls /data/data/com.alvinalexander.mybrowser
When I did that, I got an Android/ADB “permission denied” error.
The short story is that a solution to this problem is to run the same command, but with the
run-as argument, like this:
adb shell run-as com.alvinalexander.mybrowser ls /data/data/com.alvinalexander.mybrowser
The Android docs describe the
Run commands on a device as an app (specified using the package name). This lets you run commands in
adbas if the app you specify is running the command (that is, you have the same device access that the app has), without requiring root access. This might be necessary when using
adbon a non-rooted device or an emulator with a Play store image. The app must be debuggable.
I don’t have time to add much more to this right now, but one thing I’ll note is that if you have to run an ADB command where the file path has spaces in it, this command worked:
> adb shell run-as com.alvinalexander.mybrowser ls /data/data/com.alvinalexander.mybrowser/app_webview/Web\\ Data
help support my writing