I am developing Android app A so that another one B could read A's SharedPreferences.
In javadoc for android.content.Context the following is said about both MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE:
This constant was deprecated in API level 17. Creating world-writable files is very dangerous, and likely to cause security holes in applications. It is strongly discouraged; instead, applications should use more formal mechanism for interactions such as
ContentProvider,BroadcastReceiver, andService.
According to this, A shall save its SharedPreferences with MODE_PRIVATE flag and provide a ContentProvider, so that B could query A's ContentProvider. But how do I know SharedPreferences Uri?
I guess it's like content://authority_name/preference_file_name but that doesn't work for me. I would appreciate any correct examples.
And in general, is it possible to access other app's MODE_PRIVATE SharedPreferences?
MODE_PRIVATE is the operating mode for the preferences. It is the default mode and means the created file will be accessed by only the calling application. In MODE_WORLD_READABLE other application can read the created file but can not modify it.
MODE_PRIVATE. By setting this mode, the file can only be accessed using calling application. 5. MODE_WORLD_READABLE. This mode allow other application to read the preferences.
To retrieve values from shared preferences: SharedPreferences sp = PreferenceManager. getDefaultSharedPreferences(this); String name = sp. getString("Name", ""); // Second parameter is the default value.
Android Shared Preferences Overview 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() .
If your data is not so private, use sdcard storage.
It is possible to access other app's MODE_PRIVATE Sahredpreferences: they have same uid. that is, same signature and "sharedUserId" in AndroidManifest.xml.
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