What is a replacement of deprecated MODE_WORLD_READABLE SharedPreferences in Android?
Asked Answered
R

1

14

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?

Roily answered 3/4, 2014 at 6:37 Comment(7)
no, its not possible to access other app's MODE_PRIVATE Sahredpreferences. You can refer to the link developer.android.com/reference/android/content/…Reverie
@Reverie and is it possible to interface SharedPreferences with a ContentProvider if I know Provider's authorities and Preference's filename?Roily
we can't interface SharedPreferences with a ContentProviderReverie
Are both the apps developed by you?Definitive
Store the values in a database table using content provider and from there you can get the uri for the table.And from App B access those values from the uriQuanta
@Abdullah, yes, they are.Roily
@RaviTeja Creating an SQLite db and a ContentProvider just t to store a boolean seems like an overkill.Tashinatashkent
A
2

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.

Alcoholometer answered 26/2, 2016 at 3:26 Comment(2)
Could you elaborate your answer (perhaps with code)? Situation is as that I'm using the SyncAdapter pattern to notify user of an update. However, from AbstractThreadedSyncAdapter.onPerformSync() method I cannot access the app's default shared preferences using the Context passed to that method.Tashinatashkent
This answer's suggestions can lead to new difficult to solve problems when the two apps needs to exist and run on the same device...Vinegar

© 2022 - 2024 — McMap. All rights reserved.