Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

preferences - Can SharedPreferences be shared among different Android applications?

As I checked in APIs description for getSharedPreferences(String, int),Second attribute is defining accessibility mode and can take 0 or MODE_PRIVATE for the default operation, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control permissions.

But there is this small note in API description:

Note: currently this class (android.content.SharedPreferences) does not support use across multiple processes. This will be added later.

Moreover in Mark L. Murphy book "beginning Android 2" he mentioned:

(Eventually, preferences might be shareable across applications, but that is not supported as of the time of this writing)

Im so confused! does this mean that MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE of getSharedPrefrences is there but NOT SUPPORTED YET in latest API level???

Thanks! Migan

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

My book reference is based upon that comment.

Moreover, making any file MODE_WORLD_READABLE or (worse) MODE_WORLD_WRITEABLE is a bad idea. You lose any hope of security.

If you wish to share data between two applications, there are a myriad of solutions, such as:

  • service with an API exposed by AIDL
  • service with an API exposed via commands sent via startService() and responses sent via a Messenger or createPendingResult() PendingIntent or something
  • content provider
  • broadcast Intents

All of those allow you to define permissions for integration and let you control the granularity of access.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...