172

Where in an Eclipse project might one encounter a shared preferences file?

inazaruk
  • 74,247
  • 24
  • 188
  • 156
farm ostrich
  • 5,881
  • 14
  • 55
  • 81
  • I am aware that shared preference.xml is stored in data, but where is it stored before being installed; in .smali format? – sharath3589 Dec 10 '17 at 05:36

8 Answers8

270

SharedPreferences are stored in an xml file in the app data folder, i.e.

/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PREFS_NAME.xml

or the default preferences at:

/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PACKAGE_NAME_preferences.xml

SharedPreferences added during runtime are not stored in the Eclipse project.

Note: Accessing /data/data/<package_name> requires superuser privileges

sziraqui
  • 5,763
  • 3
  • 28
  • 37
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • 3
    The default shared preferences file would actually be: `/data/data//shared_prefs/_preferences.xml`. – inazaruk May 27 '11 at 00:08
  • @inazaruk It is indeed the full package name, although I see mixed uses of `/_preferences.xml` and `/.xml` on devices. Perhaps it depends on the API level of the app? – Aleadam May 27 '11 at 00:12
  • 1
    Note that I was taking about *Default* shared preferences. It looks like filename was always the same for them. See initial commit for `PreferenceManager.java`, `getDefaultSharedPreferences` function here: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/preference/PreferenceManager.java;hb=54b6cfa9a9e5b861a9930af873580d6dc20f773c#l351. And it wasn't changed in the latest version of `PrefencesManager.jave` too: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/preference/PreferenceManager.java;hb=HEAD#l353 – inazaruk May 27 '11 at 07:35
  • Any way to get the path from system, and not hard-code it? ContextImpl.java implements it in private getPreferencesDir func, it would be useful to get this at runtime somehow. – Pointer Null Mar 13 '12 at 08:28
  • You can use new FIle(context.getFilesDir().getParent(), "shared_prefs"). It does work on Nexus 5, not sure about other manufactures. – gswierczynski May 14 '15 at 18:39
  • The app makes these codes are working without rooting phone, but you should see the files on the directory of phone:../data/data folder with only rooting your Android device, but you kill the phone's warranty if you root your phone for checking the data files. – Bay Apr 07 '19 at 11:55
9

Preferences can either be set in code or can be found in res/xml/preferences.xml. You can read more about preferences on the Android SDK website.

Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
JasCav
  • 34,458
  • 20
  • 113
  • 170
  • 4
    You have to create it - as long as you have created an Android project, you can then right click on the "res" directory and add a new folder called 'xml'. Other "special" folders are anim, drawable, layout, menu, raw, and values. – JasCav May 26 '11 at 23:10
7

I just tried to get path of shared preferences below like this.This is work for me.

File f = getDatabasePath("MyPrefsFile.xml");

if (f != null)
    Log.i("TAG", f.getAbsolutePath());
Ramesh Akula
  • 5,720
  • 4
  • 43
  • 67
6

Just to save some of you time...

On my Galaxy S v.2.3.3 Shared Preferences are not stored in:/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PREFS_NAME.xml

but are now located in: /dbdata/databases/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PREFS_NAME.xml

I believe they changed this in 2.3

android-overflow
  • 745
  • 1
  • 7
  • 10
5

Shared Preferences are the key/value pairs that we can store. They are internal type of storage which means we do not have to create an external database to store it. To see it go to, 1) Go to View in the menu bar. Select Tool Windows. 2) Click on Device File Explorer. 3) Device File Explorer opens up in the right hand side. 4) Find the data folder and click on it. 5) In the data folder, you can select another data folder. 6) Try to search for your package name in this data folder. Ex: com.example.com 7) Then Click on shared_prefs and open the .xml file.

Hope this helps!

5

The data is stored on the device, in your application's private data area. It is not in an Eclipse project.

hackbod
  • 90,665
  • 16
  • 140
  • 154
1

Use http://facebook.github.io/stetho/ library to access your app's local storage with chrome inspect tools. You can find sharedPreference file under Local storage -> < your app's package name >

enter image description here

Harshit Jain
  • 142
  • 1
  • 4
0

save in /data/data/your_package_name/shared_prefs/

For see that you can use:

Android Device Monitor

Stetho

Android Debug Database

Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78