How to View an Android Shared Preferences File

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.

About Bill Lahti

Bill Lahti is a software engineer building mobile applications and knowledge management solutions. Two of his interests are writing for this blog and building Android apps, with strategy games being an area of particular interest.
This entry was posted in Android and tagged , , . Bookmark the permalink.

2 Responses to How to View an Android Shared Preferences File

  1. FrankkieNL says:

    the run-as command is broken on android 4.3

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s