Can SharedPreferences be shared among different Android applications?

蹲街弑〆低调 提交于 2019-12-17 16:37:11

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/4787785/can-sharedpreferences-be-shared-among-different-android-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!