飞行模式的开启和关闭

if(Settings.System.getString(getActivity().getContentResolver(),Settings.Global.AIRPLANE_MODE_ON).equals("0")) { Settings.System.putInt(getActivity().getContentResolver(),Settings.Global.AIRPLANE_MODE_ON,1); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state",true); getActivity().sendBroadcast(intent); Log.i(TAG,"airplane on"); } else { Settings.System.putInt(getActivity().getContentResolver(), Settings.Global.AIRPLANE_MODE_ON,0); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state",false); getActivity().sendBroadcast(intent); Log.i(TAG,"airplane off"); } <uses-permission android:name="android.permission.WRITE_SETTINGS"/> <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/> 这个权限有警告,这是由于只有系统程序才能有这个权限,个人程序是普通程序不能写这个权限要求,写了也没有用。 当在个人手机(android5.1.1)上运行时报异常: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=928, uid=10118java

这是由于个人手机API超过了4.2,必需要root以后才能有效。 网上有二篇文件介绍: http://blog.csdn.net/hrklzwzj/article/details/51940507 http://blog.csdn.net/u012889434/article/details/71248917android

相关文章
相关标签/搜索