There's an exporting feature in my application. It's just a copy operation since all my settings are store in shared preference.
I just copy the xml file from /data/data/package.name/shared_prefs/settings.xml to SD card. It works fine on my HTC desire. However, it might not work on Samsung devices, and i got the following error while I try to copy the file.
I/System.out( 3166): /data/data/package.name/shared_prefs/settings.xml (No such file or directory) in the directory.
Anyone know how to fix it, or is there another simple way to store the shared preference ?
Thanks.
Android stores Shared Preferences settings as XML file in shared_prefs folder under DATA/data/{application package} directory. The DATA folder can be obtained by calling Environment. getDataDirectory() .
Open the device monitor by clicking it. Then you need to select the File Explorer tab in the device monitor. Find the data folder and find another data folder inside it. It will contain a folder having the name of your application package and there will be the desired SharedPreferences.
SharedPreferences is used for storing data key-value pair in the Android and iOS. SharedPreferences in flutter uses NSUserDefaults on iOS and SharedPreferences on Android, providing a persistent store for simple data.
Never never never never never never never never never hardwire paths.
Unfortunately, there's no getSharedPreferenceDir()
anywhere that I can think of. The best solution I can think of will be:
new File(getFilesDir(), "../shared_prefs")
This way if a device manufacturer elects to change partition names, you are covered.
Try this and see if it helps.
Try using
context.getFilesDir().getParentFile().getAbsolutePath()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With