我想启用飞行模式,但如果启用飞行模式,我就无法使用蓝牙和WiFi。我的目的是只限制接电话和短信相关的事情。
我试过下面的方法,但没有奏效;
Settings.System.putString(getContentResolver(),
Settings.System.AIRPLANE_MODE_RADIOS, "cell,bluetooth");
有人能帮我吗
最佳答案
您可以更改当飞机模式激活时将关闭的无线电。如果在激活“空中飞机”模式之前执行此操作,则只能关闭无线蜂窝。
注意:更改飞机模式收音机会影响切换飞机的系统按钮的行为。
下面是一些在android 2.2上测试的示例代码。
// Toggle airplane mode.
Settings.System.putInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);
// Change so that only radio cell is turned off
// NOTE: This affects the behavior of the system button for
// toggling air-plane mode. You might want to reset it, in order to
// maintain the system behavior.
Settings.System.putString(context.getContentResolver,
Settings.System.AIRPLANE_MODE_RADIOS, "cell");
// Post an intent to reload.
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", !isEnabled);
sendBroadcast(intent);
关于android - 在不禁用android中的wifi和蓝牙的情况下启用飞行模式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7105750/