How can I view the shared preferences file using Android Studio?
I'm using shared preferences to store certain values for my app. I would like to see the file where the info is actually stored on my phone. I found many ways to do this on Eclipse, but I'm debugging on Android Studio. My phone is rooted. I read that having root access is important to read these types of files. If there is no way, then I will look up how to access the info through my program then output it to log cat. Hopefully, though, I can just view the file on the phone directly as it is much simpler. Thanks.
Solution 1:
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.
Solution 2:
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 shell
run-as your.app.id
chmod 777 shared_prefs/your.app.id_preferences.xml
exit # return to default user
cp /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.
Solution 3:
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
Solution 4:
Android Studio -> Device File Explorer (right bottom corner) -> data -> data -> {package.id} -> shared-prefs
Note: You need to connect mobile device to android studio and selected application should be in debug mode