Android 7.0给SharedPreferences设置Context.MODE_WORLD_READABLE或Context.MODE_WORLD_WRITEABLE,会触发SecurityException。

官方文档:
Starting from N(N is for Nougat), attempting to use this mode will throw a SecurityException.
7.0后不能这样用了。


解决办法就是:

1、Use more formal mechanism for interactions such as ContentProvider, BroadcastReceiver, and Service.

2、MODE_WORLD_READABLE 模式换成 MODE_PRIVATE

3、try catch

评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!