-2

I'm developing an android application which writes some json files into the external storage. For development I want to have a look for the written json files.

I know that I can view these files with root access in /data/data/package-name/.

But how can I get root access on the Android 7.0 Emulator?

I already tried the su command in the adb shell and also adb root - but then I get this error message: adbd cannot run as root in production builds

Maybe you have some advice?

Marcel Gangwisch
  • 8,856
  • 4
  • 23
  • 32
  • 1
    Would it be an option to try a debug build instead? – lucidbrot May 31 '17 at 14:54
  • 2
    "I know that I can view these files with root access in /data/data/package-name/" -- that is not [external storage](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html). That is [internal storage](https://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html). So... are you writing to internal storage, or external storage? – CommonsWare May 31 '17 at 14:55
  • I'm still using the debug build variant. I'm writing the json files to /data/data//files using context.getFilesDir().getPath() + "/" + fileName – Marcel Gangwisch May 31 '17 at 14:57
  • Isn't this off-topic? I think this would be better on android.stackexchange.com – Zoe May 31 '17 at 14:57
  • sorry if I put my question in the wrong place ;-) – Marcel Gangwisch May 31 '17 at 15:00

1 Answers1

5

I'm writing the json files to /data/data//files using context.getFilesDir().getPath() + "/" + fileName

That is internal storage, not external storage.

Use adb shell run-as ... ??? to run commands as your app's user, which will allow those commands to access internal storage. Here, ... is the application ID of your app, and ??? is a command.

So, for example, to list the contents of a typical location for getFilesDir() for an app whose user ID is com.foo.bar, use:

adb shell run-as com.foo.bar ls /data/data/com.foo.bar/files

This only works for debuggable apps.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491