Starting from API level 8 (Android 2.2), for the debuggable application (the one built by Android Studio all the times unless the release build was requested), you can use the shell run-as
command to run a command or executable as a specific user/application or just switch to the UID of your application so you can access its data directory.
List directory content of yourapp:
run-as com.yourapp ls -l /data/data/com.yourapp
Switch to UID of com.yourapp and run all further commands using that uid (until you call exit
):
run-as com.yourapp
cd /data/data/com.yourapp
ls -l
exit
Note 1: there is a known issue with some HTC Desire phones. Because of a non-standard owner/permissions of the /data/data
directory, run-as
command fails to run on those phones.
Note 2: As pointed in the comments by @Avio:
run-as
has issues also with Samsung Galaxy S phones running Cyanogenmod at any version (from 7 to 10.1) because on this platform /data/data
is a symlink to /datadata
. One way to solve the issue is to replace the symlink with the actual directory (unfortunately this usually requires root access).