带有 MODE_PRIVATE、MODE_WORLD_READABLE、MODE_WORLD_WRITABLE 的 Android SharedPreferences

标签 android

Android 中的

SharedPreferences 是应用程序本地的,不会在不同应用程序之间共享。当我说

SharedPreferences preferences = getSharedPreferences(PREF_NAME, MODE_WORLD_READABLE);

设置此首选项 MODE_WORLD_READABLEMODE_WORLD_WRITABLEMODE_PRIVATE?

最佳答案

getSharedPreferences(String name, int mode) 解释here

MODE_PRIVATE: File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).

MODE_WORLD_READABLE: File creation mode: allow all other applications to have read access to the created file.

MODE_WORLD_WRITEABLE : File creation mode: allow all other applications to have write access to the created file.

更多信息 here

编辑 从 API 17 开始,MODE_WORLD_READABLEMODE_WORLD_WRITEABLE 已弃用:

This constant was deprecated in API level 17.
Creating world-readable 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. There are no guarantees that this access mode will remain on a file, such as when it goes through a backup and restore.

关于带有 MODE_PRIVATE、MODE_WORLD_READABLE、MODE_WORLD_WRITABLE 的 Android SharedPreferences,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13153231/

相关文章:

android - 如何创建照片分享 Activity ?

android - Android 股票浏览器中是否有草书字体?

java - 如何将图像从 Android 上传到 Google Cloud (Java)?

java - 导出的 APK 工作正常。但通过 USB 调试不起作用

android - PhonePe 通过使用 Intent 流 UPI 集成将 null 返回到 onActivityResult

android - 拉动 View 的展开/折叠工具栏

android - 以编程方式显示/隐藏 Android 工具提示

android - 在代码下方运行时,GC 因 GC_CONCURRENT 而发疯

android - 如何从 Google 获取 api key 以进行推送通知

java - 让 edittext 显示与按下的键不同的键