How can I view the shared preferences file using Android Studio?
The Device File Explorer that is part of Android Studio 3.x is really good for exploring your preference file(s), cache items or database.
- Shared Preferences/data/data//shared_prefs directory
It looks something like this
To open The Device File Explorer:
Click View > Tool Windows > Device File Explorer or click the Device File Explorer button in the tool window bar.
From Android Studio , start Android Device Monitor, go to File Explorer, and browse "/data/data/< name of your package >/shared_prefs/". You will find the XML there... and also you can copy it for inspection.
If you have a non-rooted device it's not possible to do that directly from Android Studio. However, you can access the file with adb shell
as long as your application is the debug version.
adb shellrun-as your.app.idchmod 777 shared_prefs/your.app.id_preferences.xmlexit # return to default usercp /data/data/your.app.id/shared_prefs/your.app.id_preferences.xml /sdcard
After that you can pull the file from /sdcard directory with adb.
UPDATE: Flipper
Flipper is a newer alternative from facebook. It has more features. And actively maintained
Stetho
You can use http://facebook.github.io/stetho/ for accessing your shared preferences while your application is in the debug mode. No Root
features:
- view and edit sharedpreferences
- view and edit sqLite db
- view view heirarchy
- monitor http network requests
- view stream from the device's screen
- and more....
Basic setup:
- in the build.gradle add
compile 'com.facebook.stetho:stetho:1.5.0'
- in the application's onCreate() add
Stetho.initializeWithDefaults(this);
- in Chrome on your PC go to the chrome://inspect/
You can also use @Jeffrey suggestion:
- Open Device File Explorer (Lower Right of screen)
- Go to
data/data/com.yourAppName/shared_prefs