Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to View an Android Shared Preferences File

DZone's Guide to

How to View an Android Shared Preferences File

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

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.

android:debuggable=”true”

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.

Acknowledgement

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.

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:
java ,mobile ,android ,tips and tricks

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

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}