java.lang.SecurityException: MODE_WORLD_READABLE no longer supported

时间秒杀一切 提交于 2019-12-17 19:08:05

问题


The exception only occurs in Android 7.0 Nougat (emulator) devices.

java.lang.SecurityException: MODE_WORLD_READABLE no longer supported

My code:

public void SessionMaintainence(Context context) {
    this.context = context;
    preferences = context.getSharedPreferences(PREF_NAME, Context.MODE_WORLD_READABLE);
    editor = preferences.edit();
    editor.commit();
}

LogCat:

> E/AndroidRuntime: FATAL EXCEPTION: main
>                                                  Process: burpp.av.feedback, PID: 2796
>                                                  java.lang.RuntimeException: Unable to create application
> burpp.av.feedback.FeedbackApplication: java.lang.SecurityException:
> MODE_WORLD_READABLE no longer supported
>                                                      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5364)
>                                                      at android.app.ActivityThread.-wrap2(ActivityThread.java)
>                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
>                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
>                                                      at android.os.Looper.loop(Looper.java:154)
>                                                      at android.app.ActivityThread.main(ActivityThread.java:6077)
>                                                      at java.lang.reflect.Method.invoke(Native Method)
>                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
>                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
>                                                   Caused by: java.lang.SecurityException: MODE_WORLD_READABLE no longer supported
>                                                      at android.app.ContextImpl.checkMode(ContextImpl.java:2162)
>                                                      at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:363)
>                                                      at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:358)
>                                                      at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:164)
>                                                      at burpp.av.feedback.support.SessionMaintainence.<init>(SessionMaintainence.java:63)
>                                                      at burpp.av.feedback.FeedbackApplication.onCreate(FeedbackApplication.java:43)
>                                                      at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)

回答1:


World-readable files can be a security flaw. So android first deprecated it and then completely removed it. MODE_WORLD_READABLE was deprecated in versions till Android M. But in Android N it is no longer supported and throws SecurityException. So try a different mode. I used Context.MODE_PRIVATE and it worked.



来源:https://stackoverflow.com/questions/39121052/java-lang-securityexception-mode-world-readable-no-longer-supported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!