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

Log如下:

08-17 14:52:16.212 D/EuropeCoolWeather(20664): MainFragment click share app button
08-17 14:52:16.214 D/AndroidRuntime(20664): Shutting down VM
--------- beginning of crash
08-17 14:52:16.216 E/AndroidRuntime(20664): FATAL EXCEPTION: main
08-17 14:52:16.216 E/AndroidRuntime(20664): Process: com.europecoolweather, PID: 20664
08-17 14:52:16.216 E/AndroidRuntime(20664): java.lang.SecurityException: MODE_WORLD_READABLE no longer supported
08-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.WeatherShowActivity
08-17 14:52:16.228 D/PowerManagerService( 1737): acquireWakeLockInternal: lock=16598355, flags=0x1, tag="*launch*", ws=WorkSource{10184}, uid=1000, pid=1737
08-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    = 0
Context.MODE_APPEND    = 32768
Context.MODE_WORLD_READABLE = 1
Context.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();
}

修改之后完美解决问题;

你可能感兴趣的:(Android,BUG示例)