我想启用飞行模式,但如果我启用飞行模式,我将无法使用蓝牙、wifi。我的目的是只限制接听电话和短信相关的事情。
我尝试了以下方法,但它不起作用;
Settings.System.putString(getContentResolver(),
Settings.System.AIRPLANE_MODE_RADIOS, "cell,bluetooth");
谁能帮帮我
最佳答案
您可以更改在激活飞行模式时将关闭的 radio 。如果您在激活飞行模式之前执行此操作,则可以仅关闭 radio 小区。
注意:更改 AIRPLANE_MODE_RADIOS 会影响用于切换飞机的系统按钮的行为。
这里有一些示例代码,在 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/