0

I'm developing a library which can be used in multiple applications. The library contains a PreferenceScreen to set certain settings, which often only need to be set once.

I want to make sure the settings are shared (and able to be edited) across applications using my library and for that, I think I should set the SharedPreferences to world writable.

However PreferenceScreen seems to use the default shared preferences and although the packagename will be the same across, the mode is set to private.

How can I set the share mode for PreferenceScreen to world writable?

RobotRock
  • 4,211
  • 6
  • 46
  • 86
  • 1
    I didn't think you can install multiple apps with the same package name. – OneCricketeer Aug 06 '16 at 21:54
  • Yeah, I might be wrong on that. I was assuming it would get the package name from the library the PreferenceScreen is in, but that might not be the case. So on top of the first question, I would also very much like to know how to save the preferences of PreferenceScreen to SharedPreferences with a custom key. – RobotRock Aug 06 '16 at 21:57
  • 1
    Doesn't the preferences xml determine the key? – OneCricketeer Aug 06 '16 at 21:58
  • It doesn't in mine, but it might be possible that it could be set that way. (To clarify; by key I meant name: https://developer.android.com/reference/android/content/Context.html#getSharedPreferences(java.lang.String,%20int) ) – RobotRock Aug 06 '16 at 22:02
  • 1
    Oh, that's the name of the XML file that stores the SharedPreferences in an app's storage location. As apps cannot access other apps' storage locations, I'm not sure that string value would do any good. Basically, what you're asking for is a ContentProvider, which is the recommended way to share app data – OneCricketeer Aug 06 '16 at 22:06
  • Okay, thanks a lot cricket_007. I am totally off base then and I will look into a ContentProvider. – RobotRock Aug 06 '16 at 22:09
  • @cricket_007 [This](http://stackoverflow.com/a/11949750/1925248) actually seems to suggest that should work as intended. Are you sure you can't read preferences across apps? – RobotRock Aug 06 '16 at 22:14
  • Hmm, never tried that, but it looks like it answers your question – OneCricketeer Aug 06 '16 at 22:16
  • Well not my initial one unfortunately.. The PreferenceScreen saves to default preferences with mode private. – RobotRock Aug 06 '16 at 22:17

0 Answers0