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 /da
CommonsWare's suggestion would a be clever hack, but unfortunately it won't work.
Samsung does not always put the shared_prefs directory in the same parent directory as the getFilesDir()
.
I'd recommend testing for the existence of (hardcode it, except for package name):
/dbdata/databases/
and if it exists use it, otherwise fall back to either CommonsWare's suggestion of new File(getFilesDir(), "../shared_prefs")
or just /data/data/
.
A warning though that this method could potentially have problems if a user switched from a Samsung rom to a custom rom without wiping, as the /dbdata/databases
file might be unused but still exist.
On some Samsung devices, such as the Galaxy S series running froyo, the setup is this:
/data/data//(lib|files|databases)
Sometimes there's a shared_prefs there too, but it's just Samsung's attempt to confuse you! Don't trust it! (I think it can happen as a left over from a 2.1 upgrade to 2.2, but it might be a left over from users switching roms. I don't really know, I just have both included in my app's bug report interface and sometimes see both files).
And:
/dbdata/databases//shared_prefs
That's the real shared_prefs directory.
However on the Galaxy Tab on Froyo, it's weird. Generally you have: /data/data/
With no /dbdata/databases/
directory, but it seems the system apps do have:
/dbdata/databases/
And added bonus is that /dbdata/databases/
is not removed when your app is uninstalled. Good luck using SharedPreferences if the user ever reinstalls your app!