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?

Mangesh
  • 5,491
  • 5
  • 48
  • 71
Jay Foreman
  • 600
  • 1
  • 6
  • 17
  • 3
    no, its not possible to access other app's MODE_PRIVATE Sahredpreferences. You can refer to the link http://developer.android.com/reference/android/content/Context.html#MODE_PRIVATE – Madhu Apr 03 '14 at 06:55
  • @Madhu and is it possible to interface SharedPreferences with a ContentProvider if I know Provider's authorities and Preference's filename? – Jay Foreman Apr 03 '14 at 07:16
  • 1
    we can't interface SharedPreferences with a ContentProvider – Madhu Apr 03 '14 at 08:33
  • Are both the apps developed by you? – Abdullah Feb 25 '16 at 04:52
  • 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 uri – Ravi Theja Feb 25 '16 at 07:51
  • @Abdullah, yes, they are. – Jay Foreman Feb 26 '16 at 13:43
  • @RaviTeja Creating an SQLite db and a ContentProvider just t to store a boolean seems like an overkill. – fahmy Feb 26 '16 at 14:27

1 Answers1

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.

Swing
  • 858
  • 1
  • 8
  • 21
  • Could you elaborate your answer (perhaps with code)? Situation is as that I'm using the [SyncAdapter](http://developer.android.com/training/sync-adapters/creating-sync-adapter.html) 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. – fahmy Feb 26 '16 at 15:48
  • 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... – Maria Aug 17 '16 at 09:50