1.核心代码如下:

public static void openAirplaneModeOn(Context context,boolean enabling) {      Settings.Global.putInt(context.getContentResolver(),                       Settings.Global.AIRPLANE_MODE_ON,enabling ? 1 : 0);  Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);  intent.putExtra("state", enabling);  context.sendBroadcast(intent);} 

2.AndroidManifest.xml权限

   

3.说明如下

public static void setAirplaneModeOn(Context context,boolean enabling) {      Settings.System.putInt(context.getContentResolver(),                           Settings.System.AIRPLANE_MODE_ON,enabling ? 1 : 0);      Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);      intent.putExtra("state", enabling);      context.sendBroadcast(intent);  } 
之前用上述的代码,始终报这样的错误:java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=25190, uid=10081,后来查看了系统源码 ,终于发现了端倪,原来AIRPLANE_MODE_ON 从Setting.System下移到了Settings.Global下。所以在4.2以上的版本app没有权限修改Setting.Global的,解决的办法就是把应用放到源码中去编译,并且加上
权限。

更多相关文章

  1. Android 10 文件读写权限申请
  2. Android对应用程序的资源文件xml解析的源代码在哪里
  3. android 6.0权限全面详细分析和解决方案
  4. android:软件的安装和卸载源代码
  5. Android高版本P/Q/R源码编译指南
  6. 向Android社区贡献代码过程详解
  7. Android(Kotlin版本)MVC框架的实例以及代码

随机推荐

  1. Google Maps API申请 之 Android(安卓)Ma
  2. 生成so
  3. Android的Animation之LayoutAnimation使
  4. ArcGIS Runtime SDK for Android(安卓)v1
  5. Android(安卓)Service完全解析(下)
  6. Android(安卓)Studio试用说明
  7. android游戏引擎andengine学习系列六:Phy
  8. 【ALearning】第五章 Android相关组件介
  9. Android(安卓)WiFi系统
  10. Android(安卓)四大组件(Activity、Servic