Android 4.2 After the system does not allow third-party software to set up flight mode, unless your app is a system application, get root permissions
Gets the current flight mode status needs to be modified according to different Android versions @suppresswarnings ("Deprecation") public boolean Isairplanemodeon () { //4.2 below if (Build.VERSION.SDK_INT < Build.version_codes. JELLY_BEAN_MR1) { Return Settings.System.getInt (Getcontentresolver (), settings.system.airplane_mode_on, 0)! = 0; } else//4.2 or more than 4.2 { return Settings.Global.getInt (Getcontentresolver (), settings.global.airplane_mode_on, 0)! = 0; } }
Set Airplane mode @suppresswarnings ("deprecation") public void Setairplanemodeon (Boolean isenable) {if (Build.VERSION.SDK_INT & Lt Build.version_codes. JELLY_BEAN_MR1) {Settings.System.putInt (Getcontentresolver (), Settings.System.AIRPLANE_M Ode_on,isenable? 1:0); } else//4.2 or 4.2 or more {Settings.Global.putInt (Getcontentresolver (), global.airplane_mode_on, isenable? 1:0); } Intent Intent = new Intent (intent.action_airplane_mode_changed); Intent.putextra ("state", isenable); Sendbroadcast (Intent); }
Note that, in the 4.2 app is actually no permission to modify Setting.global, the solution is to put your app in the system's System/app directory, and then install. This way, the app becomes the system app, and you get permission to write Setting.global.
Android 4.2 system after flight mode