Android 7.0 java.lang.SecurityException: MODE_WORLD_READABLE no longer supported闪退

来源:互联网 发布:如何windows截屏 编辑:程序博客网 时间:2024/06/02 05:19

Log如下:

08-17 14:52:16.212 D/EuropeCoolWeather(20664): MainFragment click share app button08-17 14:52:16.214 D/AndroidRuntime(20664): Shutting down VM--------- beginning of crash08-17 14:52:16.216 E/AndroidRuntime(20664): FATAL EXCEPTION: main08-17 14:52:16.216 E/AndroidRuntime(20664): Process: com.europecoolweather, PID: 2066408-17 14:52:16.216 E/AndroidRuntime(20664): java.lang.SecurityException: MODE_WORLD_READABLE no longer supported08-17 14:52:16.216 E/AndroidRuntime(20664): at android.app.ContextImpl.checkMode(ContextImpl.java:2134)08-17 14:52:16.216 E/AndroidRuntime(20664): at android.app.ContextImpl.openFileOutput(ContextImpl.java:481)08-17 14:52:16.216 E/AndroidRuntime(20664): at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:192)08-17 14:52:16.216 E/AndroidRuntime(20664): at com.europecoolweather.util.ShareApp.shareApp(ShareApp.java:25)08-17 14:52:16.216 E/AndroidRuntime(20664): at com.europecoolweather.Fragment.MainFragment.onClick(MainFragment.java:71)08-17 14:52:16.216 E/AndroidRuntime(20664): at android.view.View.performClick(View.java:5640)08-17 14:52:16.216 E/AndroidRuntime(20664): at android.view.View$PerformClick.run(View.java:22455)08-17 14:52:16.216 E/AndroidRuntime(20664): at android.os.Handler.handleCallback(Handler.java:751)08-17 14:52:16.216 E/AndroidRuntime(20664): at android.os.Handler.dispatchMessage(Handler.java:95)08-17 14:52:16.216 E/AndroidRuntime(20664): at android.os.Looper.loop(Looper.java:154)08-17 14:52:16.216 E/AndroidRuntime(20664): at android.app.ActivityThread.main(ActivityThread.java:6165)08-17 14:52:16.216 E/AndroidRuntime(20664): at java.lang.reflect.Method.invoke(Native Method)08-17 14:52:16.216 E/AndroidRuntime(20664): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)08-17 14:52:16.216 E/AndroidRuntime(20664): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)08-17 14:52:16.221 W/ActivityManager( 1737):   Force finishing activity com.europecoolweather/.activity.WeatherShowActivity08-17 14:52:16.228 D/PowerManagerService( 1737): acquireWakeLockInternal: lock=16598355, flags=0x1, tag="*launch*", ws=WorkSource{10184}, uid=1000, pid=173708-17 14:52:16.229 I/KPI-6PA-AT-1(20664): 252532952 enter ActivityThread.schedulePauseActivity() : android.os.BinderProxy@8e956e1


源代码:

FileOutputStream fileOutputStream=null;try {fileOutputStream = mActivity.openFileOutput("share.png",1);} catch (FileNotFoundException e) {e.printStackTrace();}

意思是MODE_WORLD_READABLE 模式已经被废弃。将1修改为MODE_PRIVATE


四种模式,分别为: 

Context.MODE_PRIVATE    = 0Context.MODE_APPEND    = 32768Context.MODE_WORLD_READABLE = 1Context.MODE_WORLD_WRITEABLE = 2

所以修改代码如下:

FileOutputStream fileOutputStream=null;try {fileOutputStream = mActivity.openFileOutput("share.png",MODE_PRIVATE);} catch (FileNotFoundException e) {DebugLog.d(TAG,"File Not Found Exception");e.printStackTrace();}

修改之后完美解决问题;

阅读全文
0 0