How to examine SharedPreferences from adb shell?

Fine, I found the file just after I raised the question above. (It seem asking questions publicly stimulate me to search answers by myself much more diligently, since I don't want my dear peers to view me as a lazy programmer.)

It is an XML file under /data/data/your.app.package.name/shared_prefs, and the file name is your.app.package.name_preferences.xml. It is really easy to modify the preferences when you figure out that the content is just a key-value map.


If the app is debugable you could do:

$ adb shell
$ run-as <app-package-id>
$ cat /data/data/<app-package-id>/shared_prefs/prefs.xml

Note that the preference might be stored in another file so better check the directory to find it:

$ ls /data/data/<app-package-id>/shared_prefs/

I am using this convenient one-liner to pull, edit in vim, and push shared preferences for an app:

APP_ID=com.myapp; adb pull /data/data/${APP_ID}/shared_prefs/${APP_ID}_preferences.xml /tmp/${APP_ID}_preferences.xml && vim /tmp/${APP_ID}_preferences.xml && adb push /tmp/${APP_ID}_preferences.xml /data/data/${APP_ID}/shared_prefs/

Just set APP_ID to your application id.

Note that this assumes you are using the default file name for shared preferences, as obtained from PreferenceManager.getDefaultSharedPreferences(context). Also, ADB needs to be running in root mode: adb root