This is first post in a series I call Android snippets. Snippets are short posts that contain actionable items that will come handy in Android development. So let’s get to the first snippet.
When you develop your Android app, you sometimes want to access the files written by the app to the device disk. If you’re developing with an emulator, accessing the files is easy with either the Android Device Monitor or adb shell. But if you’re running your app on a real device, accessing the files requires a rooted device… Except that isn’t exactly true. You can access application private files on any device if the app is build with debug mode enabled.
If the app has debug mode enabled, you can access the files in adb shell by changing the shell user:
$ run-as <applicationId>
For example, let’s say that I’ve been developing an app with applicationId of com.tanelikorri.example. To access the app’s private files, I need to start adb shell and give the following command:
$ adb shell angler:/ $ run-as com.tanelikorri.example
That’s all there is to it. After that you can access the files with adb file transfer commands like push and pull.