zoukankan      html  css  js  c++  java
  • Android-Android7.0-java.lang.SecurityException: MODE_WORLD_READABLE no longer supported

    某个AndroidProject项目在Android5.0系统运行是OK的,在Android7.0以上版本运行,报以下错误❌

    2019-01-02 15:33:39.996 17067-17067/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: liudeli.music2:remote, PID: 17067
    java.lang.RuntimeException: Unable to create service liudeli.music2.service.MediaPlaybackService: java.lang.SecurityException: MODE_WORLD_READABLE no longer supported
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3226)
    at android.app.ActivityThread.-wrap5(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1586)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6186)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
    Caused by: java.lang.SecurityException: MODE_WORLD_READABLE no longer supported
    at android.app.ContextImpl.checkMode(ContextImpl.java:2134)
    at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:354)
    at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:349)
    at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:164)
    at liudeli.music2.service.MediaPlaybackService.onCreate(MediaPlaybackService.java:345)


    解决方法:

    // mPreferences = getSharedPreferences("Music", MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
    mPreferences = getSharedPreferences("music", MODE_PRIVATE);

    把 MODE_WORLD_READABLE 更换成 MODE_PRIVATE 即可,因为MODE_WORLD_READABLE 模式已经被废弃

  • 相关阅读:
    Knol of Fabio Maulo
    调用非.net系统的Webservice的探索 ( 二 ) WSE
    在Sql Server 使用系统存储过程sp_rename修改表名或列名
    Who is locking the DB account?
    (python learn) 7 字典
    (python learn) 8 流程控制
    (python learn) 4 number&& string
    where is the data come from after we drop the table
    (healthy recorder) 治疗第6天
    (python learn) 6 列表
  • 原文地址:https://www.cnblogs.com/android-deli/p/10208921.html
Copyright © 2011-2022 走看看