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