How to View an Android Shared Preferences File

DZone 's Guide to

How to View an Android Shared Preferences File

· Mobile Zone ·
Free Resource

Here is what I do when I want to see the contents of an Android Shared Preferences file when I am debugging an app.

1. Change the AndroidManifest.xml so the app is debuggable. Add a line in the <application> tag.


2. In Eclipse, run the application in the debugger. That is the “Run – Debug as …” menu item.

3. Run the app until you get to the point where you want to see the contents of a shared preferences file

4. Then start a terminal session and do the following commands after using the Android Debug Bridge (ADB) to start a shell.

adb shell
 $ run-as com.wglxy.starship
 $ ls

 $ cd shared_prefs
 $ ls
 $ cat game_data.xml

For your own app, be sure to replace the text in italics with your app’s package name and the name of the shared preferences file you want.

The two ls commands are there to reassure yourself that you are in the right place. The last command (cat) copies the contents of the shared preferences file to the Terminal window. After that, I usually copy all of the text from the Terminal windows to an editor or text viewer so I can take a close look at it.

I do not know exactly where this works. I work in Eclipse Indigo on a Macbook.  These steps work fine with my Nexus 7 tablet, which is running Android 4.4.2. However, it does not work on my Galaxy Nexus phone (Android 4.3).

Sorry for the imperfect solution, but I thought it would be better to share a partial solution because, when it does work, it is quick way to see what is going into your shared preferences files.


Thanks go to Dennis Kubes for writing “Read Android Data Folder Without Rooting“. It took me a while to figure out which devices I could use his suggestions for, but now I use it all the time.

android ,java ,mobile ,tips and tricks

Published at DZone with permission of Bill Lahti . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}