我试图在Android 4.2.2的Nexus 4中设置飞机模式.我知道这是不可能的,因为AIRPLANE_MODE_ON已移至全局系统设置,它只是一个读取选项.
有没有其他方法可以做类似的事情,我的意思是禁用收音机?我可以禁用蓝牙,wifi和互联网连接,但电话呼叫网络仍然有效.
是否可以使用NDK创建一个库以完全禁用网络?
编辑:我试过java.lang.reflect这个方法:
@SuppressLint("NewApi")
@SuppressWarnings("rawtypes")
private boolean putStringAirplaneMode() throws ClassNotFoundException,
NoSuchMethodException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
ContentResolver resolver = context.getContentResolver();
String name = Settings.Global.AIRPLANE_MODE_ON;
String value = (isEnabled() ? "1" : "0");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Log.v("AirplaneBatterySaver",
"Using reflection to change airplane mode");
// For JELLY_BEAN_MR1 use reflection. TODO test if works reflection
Class SystemProperties = android.provider.Settings.Global.class;
Class[] parameterTypes = new Class[3];
parameterTypes[0] = ContentResolver.class;
parameterTypes[1] = String.class;
parameterTypes[2] = …Run Code Online (Sandbox Code Playgroud)