Shared Preference Directory - genymotion - android

I work on a application that save data on shared preferences
when I using AVD for test my app shared preference file exist in below directory and all things is ok
/data/data/MY_PACKAGE_NAME/shared_prefs/setting.xml
But when I use Genymotion, data folder is empty in eclipse file explorer.
How could I access to shared preferences?

i find my answer here.
this problem Happens when we have not appropriate permissions

Related

How to refresh SharedPreferences after adding an xml file to its storage location

I have the following problem: Since I want to keep my shared preference data even if the .apk is uninstalled I copy its .xml file to an external location as described here: Android Backup of ENTIRE SharedPreferences file. However, after reinstalling the app and starting the application I import the .xml to the shared preferences location but it won't be found by the app at the very first time. It works after shutting the app down and restarting it again. What can I do that it already works from the beginning? It seems like to be necessary to refresh the shared preferences directory, but how can that be done within the app?
Thanks in advance
You can put files in a directory derived from Environment.getExternalStorageDirectory(). These files will persist after an uninstall. However, a user can delete those files any time they like, regardless of whether your app is installed or not.

Android SharedPreferences for files outside the shared_prefs directory

Specifically I want to create a shared preferences file in the no_backup directory, inside which it is recommended for Android 6.0 apps to store device specific information like installation id and GCM tokens.
However, the getSharedPreferences method in Context and getDefaultSharedPreferences method in PreferenceManager only allows me to modify files inside the shared_prefs directory.
Is there any solution to store simple preferences in the no_backup folder without resorting to custom solutions?
find the app files directory by getFilesDir, let it be filesDir
you can operate the shared_prefs files with path filesDir/../shared_prefs/<preference name>.xml

does variables in shared preferences share accross applications?

I want to share variable between two android application so I stored it in shared preference but when I reinstalled the application that store the variable the second application didn't see the variable, what is the best way to share variable between two application and dealing with situation when one of them will be reinstalled
I used this code
SharedPreferences globals_prefs = ctx.getSharedPreferences("globals_prefs", Context.MODE_WORLD_WRITEABLE);
The SharedPreferences in one application is stored as a prefs.xml file in a separate folder dedicated for you app in the Android File System. So when you uninstall an app, this folder also is deleted, thereby, all Preferences made by your app is removed. So a better way is to use Files to store it in the sdCard.
Note: currently this class does not support use across multiple processes. This will be added later.
From android dev documents
http://developer.android.com/reference/android/content/SharedPreferences.html
File or sqlite database on public directory would do the trick when sharing data
When you uninstall an app shared preference and internal cache is wiped out, so the only way is to use external storage.

Where are shared preferences stored?

Where in an Eclipse project might one encounter a shared preferences file?
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
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.
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());
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
The data is stored on the device, in your application's private data area. It is not in an Eclipse project.
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!
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 >
save in /data/data/your_package_name/shared_prefs/
For see that you can use:
Android Device Monitor
Stetho
Android Debug Database

How to change the android sharedPreferences save path?

I want to change the android sharedPreferences save path,the sharedPreferences save in /data/data/xxx.xxx.xxx/shared_prefs,i want to change path to /sdcard. how i do?
You cannot modify where shared preferences are stored. Since shared preferences are simply stored in an XML file, you are welcome to read and write XML data on external storage as you see fit.
BTW, never use /sdcard. Use Environment.getExternalStorageDirectory(). /sdcard is not the correct path for over a third of existing Android devices.

Categories

Resources