Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a replacement of deprecated MODE_WORLD_READABLE SharedPreferences in Android?

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, and Service.

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?

like image 233
Jay Foreman Avatar asked Apr 03 '14 06:04

Jay Foreman


People also ask

What is Mode_private?

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.

What is Mode_private when creating shared preference file?

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.

How save and retrieve data using SharedPreferences in Android?

To retrieve values from shared preferences: SharedPreferences sp = PreferenceManager. getDefaultSharedPreferences(this); String name = sp. getString("Name", ""); // Second parameter is the default value.

Where is shared preference file stored android?

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() .


1 Answers

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.

like image 172
Swing Avatar answered Sep 19 '22 11:09

Swing