不能再通过createPackageContext来访问另外一个应用的资源(Sharepreference)

以前我们可以通过createPackageContext来访问另外一个应用的资源(Sharepreference),但Android 7.0以后为了安全性,丢弃了这种方式了
PS:
/**
* File creation mode: allow all other applications to have read access to
* the created file.
* <p>
* As of {@link android.os.Build.VERSION_CODES#N} attempting to use this
* mode will throw a {@link SecurityException}.
*
* @deprecated 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 {@link ContentProvider},
* {@link BroadcastReceiver}, and {@link android.app.Service}.
* There are no guarantees that this access mode will remain on
* a file, such as when it goes through a backup and restore.
* @see android.support.v4.content.FileProvider
* @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
*/
@Deprecated
public static final int MODE_WORLD_READABLE = 0x0001;

若再尝试使用MODE_WORLD_READABLE 这种方式来建立SharePreference 会报SecurityException。

01-08 05:32:21.465 16339 16339 E AndroidRuntime: Caused by: java.lang.SecurityException: MODE_WORLD_READABLE no longer supported
01-08 05:32:21.465 16339 16339 E AndroidRuntime: at android.app.ContextImpl.checkMode(ContextImpl.java:2134)
01-08 05:32:21.465 16339 16339 E AndroidRuntime: at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:354)
01-08 05:32:21.465 16339 16339 E AndroidRuntime: at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:349)
01-08 05:32:21.465 16339 16339 E AndroidRuntime: at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:164)
01-08 05:32:21.465 16339 16339 E AndroidRuntime: at com.android.deskclock.Utils.getCESharedPreferences(Utils.java:778)
01-08 05:32:21.465 16339 16339 E AndroidRuntime: at com.android.deskclock.settings.DefaultAlarmToneDialog.<init>(DefaultAlarmToneDialog.java:74)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值