共享preferences可以是私有? [英] Can Shared Preferences be private?

查看:96
本文介绍了共享preferences可以是私有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单从名字,我猜测共享preferences 是...应用程序之间共享? 也就是说,即使我的应用程序定义和创建它们,在Android上任何应用程序可以访问它们。这是正确的?

From the name alone, I am guessing that Shared Preferences are... shared among apps? That is, even if my app defines and creates them, any app on android can access them. Is this correct?

(如果这是不正确的,那么为什么在数据存储开发指南强调内部存储为存储私人数据?)

(If this isn't correct, then why does the Data Storage Dev Guide emphasize Internal Storage as "Store private data"?)

如果这是正确的,我可以修改这个默认行为,从而使preference是在我定义和创建它的应用程序,唯一可见的?

If this is correct, can I modify this default behavior so that a preference is only visible from the app in which I define and create it?

如果是这样,我该怎么做呢?

If so, how do I do that?

推荐答案

如果我是正确的,你可以通过调用使其存储的私人

If i'm correct you can make store it as private by calling

getShared preferences(yourfile,MODE_PRIVATE);

getSharedPreferences(yourfile, MODE_PRIVATE);

公共静态最终诠释MODE_PRIVATE 自:API级别1 文件创建模式:默认模式,其中所创建的文件只能通过调用应用程序(或共享相同的用户ID的所有的应用程序)访问的

public static final int MODE_PRIVATE Since: API Level 1 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 MODE_WORLD_WRITEABLE 恒值:0(00000000)

See Also MODE_WORLD_READABLE MODE_WORLD_WRITEABLE Constant Value: 0 (0x00000000)

这篇关于共享preferences可以是私有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆