Modify AIRPLANE_MODE_ON on Android 4.2 (and above)

2019-01-17 17:11发布

问题:

Since the sdk version 4.2 it seems like it's no longer possible to modify airplane-mode on devices since google has moved this setting to Settings.Global which is read-only.

Has anyone been able to bypass this without and kind of rooting?

My apps primary function is to enable airplane-mode when the screen is turned off, and this stopped working since 4.2.

Just want to double check that my assessment is correct and that my app is dead starting from android 4.2 and above.

References: http://developer.android.com/reference/android/provider/Settings.Global.html#AIRPLANE_MODE_ON

回答1:

I know you explicitly ask for a solution without rooting, but if you have a rooted device there is at least the (kind of) official solution to move your app into folder /system/app. Then it is possible to write into Settings.Global:

Settings.Global.putInt(context.getContentResolver(), Global.AIRPLANE_MODE_ON, mode ? 1 : 0);

Have a look of how to toggle airplane mode for 4.2 and how to move your app into /system/app here. I use this for my toggle widget Mini Status (source code link).



回答2:

Just want to double check that my assessment is correct and that my app is dead starting from android 4.2 and above.

Yes. Or, to put it another way, if there is a back-door way to modify this setting, it represents a security hole, which will eventually get closed, much like the enable/disable GPS restriction that has existed for 3+ years.