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
Related
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.
I have created a file inside one folder in android and I have encrypted that file. When user clicks "READ" button in my app, the specified file will be decrypted in same folder. but I want the users not to access those files via USB or file manager. How to implement this concept?
Use this
context.getDir(null, Context.MODE_PRIVATE);
In place of
context.getExternalCacheDir()
This will solve your problem.
I've created an app using Android Studio and it has a database file handler. I've gone through a few post and everywhere they are saying go to data\data\ folder to get the app folder. But mine doesn't show any folder for my app. Do I have to manually set this file location to be created? How can I find my database.db file?
It should be automatically placed in data/data/databases in your app folder unless you specify otherwise. Are you sure it is created?
That is /data/data/package-name/databases/dbfilename
I have another suggestion. If you have enabled backup for your application, you might be able to use ADB BACKUP, like suggested here: http://blog.shvetsov.com/2012/09/backup-your-android-without-root-or.html
The database files are located in the following folders.
/data/data/packagename/databases/
You can access the .db file only on emulator, its not possible on actual device. In the android studio open the DDMS perspective, there on the left hand side you will find the storage structure, there in data/data/ you will get the file you are looking for
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
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.