android - 启用飞行模式而不禁用android中的wifi和蓝牙

标签 android

我想启用飞行模式,但如果我启用飞行模式,我将无法使用蓝牙、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/

相关文章:

java - WebDriverException : It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream 和 long 未找到

android - 有多个闹钟时取消单个闹钟

android - 检测 toast 消息

android - xml 中的单个 fragment 给出预览错误 : "Cyclic include, not valid"

android - 如何以编程方式设置recyclerview的高度?

android - 从 android 中的服务访问共享 SharedPreference

java - MismatchSenderId 错误 Firebase 云消息传递 (FCM)

android - 使用缩放和滚动打开 ImageView

android - 如何检测 Google Play 购买是从测试帐户还是普通帐户进行的

android - 如何在android中获取捕获视频的持续时间?