24

I have an xml file being written by an app that is set to MODE_PRIVATE, but I now want to read that file outside of the phone, for debugging purposes. In Eclipse, I can access other files made by the app and copy them to my computer, but I can't even see this private file. Merely changing the file to MODE_WORLD_READABLE file doesn't seem to help. I think the file is being stored on an internal "SD card" that can not be removed from the phone, but there are also two other folders in the File Explorer that are either empty or inaccessible: asec and secure.

Does anyone know how the file can be accessed?

5 Answers 5

48

If your app is installed in debug mode, you can get your private files on a device without rooting.

  1. Go to [android-sdk]/platform-tools folder and run adb shell.
  2. run-as com.example.yourapp
  3. cp -r /data/data/com.example.yourapp /sdcard/

(Where com.example.yourapp is the package name of your application.) After executing the steps above, the private folder of your application is copied into the root of your sdcard storage, under your package name, where you have permission to download and view them.

Note 1: If you don't need to download them, then instead of step 3, you can use unix commands to navigate around and list files and folders.

Note 2: Starting from Android Studio 2.0, you'll find more files in the cache and files/instant-run folder, related to the Instant Run and the GPU Debugger features, placed there by the IDE.

5
  • Just what I was looking for, without rooting. I tried extracting the file using the Android File Transfer(for access from mac), but the come.example... file that I coped to sdcard folder doesnt showup in there. I eventually ended up sharing it manually from the phone's explorer window. Any better way? Thanks.
    – Jas
    Apr 16, 2016 at 17:28
  • 2
    @Jas - you can also use the adb pull command to download the folder. Apr 18, 2016 at 9:53
  • 1
    This does not work on Samsung devices running Android 6.0.1: code.google.com/p/android/issues/detail?id=206581#c4
    – ChristophK
    May 25, 2016 at 9:37
  • I often run a real device and an emulator. "adb -e shell" will open a shell on the emulator, while "adb -d shell" will open a shell for the USB attached device. No luck grabbing files though on my Galaxy S5, even with running "run-as com.android.myapp" first. But it does work on the emulator.
    – Les
    Jan 23, 2017 at 19:24
  • I get permission denied on step 3. I'm running it on a Google Pixel Emulator Android 8.0. Any ideas?
    – Ivan
    Jun 25, 2018 at 17:43
21

You will need to connect the phone and do some magic to let your sdk work with it (I think put it in debugging mode?). Go to where you unzipped the android sdk:

C:\android-sdk_r10-windows\android-sdk-windows\platform-tools>adb shell
#cd data/data/com.yourpackage.yourapp/files
#ls

You should see your file listed. You may need to run "ls data/data" if you're not sure what the fully-qualified name of your app is. From here if the file is small and you just want to see what's inside it you can run:

#cat yourfilename.xml

Alternatively:

#exit
C:\android-sdk_r10-windows\android-sdk-windows\platform-tools>adb pull /data/data/com.yourpackage.yourapp/files/yourfile.xml

Note: I have only tried this on the emulator, I don't know how to use adb with a physical phone.

2
  • 3
    Also, I can confirm it doesn't work on a real phone (which is probably as it should be). At least, it doesn't work on my Galaxy S1. Aug 19, 2012 at 23:00
  • adb shell su to grant superuser (root) Jun 15, 2019 at 1:18
4

You need to root your phone to see Context.MODE_PRIVATE files

It ends up being stored in data//files I believe but you need root permission to see them

So either root your phone or wait until you finished debugging and then add Context.MODE_PRIVATE

2

If Eclipse is used, there is one more option:

DDMS Perspective > File Explorer tab > data/data/com.yourpackage.yourapp/files

where you can pull/push/delete files.

0

Another option is to have a command in the app that dumps the private files. This only works if you don't want to edit the files, but has the added bonus that you don't have to strip it out before it goes to production, because the user can't break anything with it. Well, as long as the files don't contain sensitive information. But, really, if they do, you're doing something wrong. As @user1778055 said, a user can root their phone to access it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.