world readable preferences can be accessed by other apps. You just
have to use the Context of the owning app.
Context myContext = createPackageContext("com.example",
Context.MODE_WORLD_WRITEABLE);
SharedPreferences testPrefs = myContext.getSharedPreferences
("test_prefs", Context.MODE_WORLD_READABLE);
boolean valueFromPrefs = testPrefs.getBoolean("test_key", false);
On Oct 26, 11:20 pm, James <[email protected]> wrote:
> The shared preferences is for all components associated with the same
> package (and possibly task/affinity). The key you give it is just a
> key for a map lookup. The permissions have to do with if the
> information can be shared or changed with other components in the
> package. Also, I think you need to still save those preferences
> either to a file or the database if you want them to remain after the
> process containing all the components close. From your description I
> do not think the shared preference behavior is what you want? A quick
> and dirty way, if you have this in your control, is to change all the
> uid's for your applications to the same and use the file api's for
> reading and writing from a file or the database. Using a database is
> just a step away from using a content provider though... which is
> probably the correct most solution.
>
> On Oct 26, 12:42 pm, sandy8531 <[email protected]> wrote:
>
> > I have a need to share preferences between two apps, where one app
> > writes the preferences and the other needs read only access.
>
> > I notice that there is this API available in Context :
>
> > public abstract SharedPreferences getSharedPreferences (String
> > name, int mode). Where I can set the mode to : MODE_WORLD_READABLE
> > which according to docs means that it will allow all other
> > applications to have read access to the created file.
>
> > My question is : What should be my filename so that the file gets
> > created and is shared between the apps.
>
> > If I give a relative path (getSahredPrefs("filename",
> > MODE_WORLD_READABLE)) then it gets created in the "data" directory of
> > the writing app and the other non creating application is not able to
> > get to it using the same arguments i.e. - getSahredPrefs("filename",
> > MODE_WORLD_READABLE).
>
> > So I assume I need to provide a absolute path - something like ("/data/
> > data/<pkgname>/<subdir>/filename", MODE_WORLD_READABLE) but I do not
> > know how to construct that generically using provided APIs so that it
> > works on every Android phone/image.
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en