当前位置: 首页 > 知识库问答 >
问题:

在Android 4.4禁用蜂窝无线电

梁勇
2023-03-14

如何在android中禁用/启用蜂窝网络?我需要在短时间内完全禁用它,因为我有android 4.4飞行模式很难使用。

是否可以编写仅禁用蜂窝网络的代码?

共有1个答案

任元青
2023-03-14

控制飞机模式

检查是否已启用:

boolean isEnabled = Settings.System.getInt(
      context.getContentResolver(), 
      Settings.System.AIRPLANE_MODE_ON, 0) == 1;

切换它:

// toggle airplane mode
Settings.System.putInt(
      context.getContentResolver(),
      Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);

// Post an intent to reload
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", !isEnabled);
sendBroadcast(intent);

您可以使用此功能:

/* Toggle airplane mode for 1 of the 4 allowed types
 * type allowed values: cell, wifi, bluetooth, nfc
 */
private void changeRadioComponentEnabled(Context context, String type, boolean radio_component_enabled, boolean reset){     
        // now toggle airplane mode from on to off, or vice versa
        Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, radio_component_enabled ? 0 : 1);

        // now change system behavior so that only one component is turned off
        // this also affects the future behavior of the system button for toggling air-plane mode. 
        // to reset it in order to maintain the system behavior, set reset to true, otherwise we lazily make sure mobile voice is always on
        Settings.System.putString(context.getContentResolver(), Settings.System.AIRPLANE_MODE_RADIOS, type); 

        // post an intent to reload so the menu button switches to the new state we set
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", radio_component_enabled ? false : true);
        context.sendBroadcast(intent);

        // revert to default system behavior or not
        if (reset){ Settings.System.putString(context.getContentResolver(), Settings.System.AIRPLANE_MODE_RADIOS, "cell,bluetooth,wifi,nfc"); }
        // if reset to default is not chosen, always enable mobile cell at  least
        // but only if NOT changing the mobile connection...
        else if (type.indexOf("cell") == 0) { Settings.System.putString(context.getContentResolver(), Settings.System.AIRPLANE_MODE_RADIOS, "cell");}
}//end method

您需要android的权限。准许写入设置

阅读更多:

http://dustinbreese.blogspot.com/2009/04/andoid-controlling-airplane-mode.html

如何以编程方式禁用Android中的GSM连接

编辑:我读到这种方法不再可能使用Android 4.2及以上版本。但我认为您可以阅读一些有趣的代码:

如何打开/关闭飞行模式,即使在新的Android版本上(甚至使用root)?

在Android中切换飞机模式

 类似资料:
  • 蜂窝利用 目前,我们已经知道了如何在头单元上运行代码,前提是你能用USB设备(劫持)来连接汽车或访问车内的Wi-Fi(利用D-BUS漏洞/功能)。最大的问题是,这些入侵方法都要么需要接触到汽车,要么就需要攻击者加入到车上的Wi-Fi热点。 如果能加入到车内的Wi-Fi热点并进行漏洞利用是非常让人激动的,因为这就说明我们已经远程入侵了一辆原装汽车,但是,对我们来说,这其中的前提和限制还是太多了。首先

  • 我在为我的工作监视蜂窝天线。使用SIM800L芯片(2G)和SIM71200A(3G、4G),并使用不同的AT命令,我得到了附近天线和发射功率的列表。有了这些数据,我就可以把它们定位在某个区域,然后拍下来。 备选方案1:MCC+MNC+LAC+CELID 备选方案2:中冶集团+跨国公司+拉加集团+黑海国家集团 备选方案3:MCC+MNC+BSIC PD:AT命令为:AT+ceng、AT+crus和

  • 我们正在从Android应用程序进行大量上传。我们希望强制这些用户使用WiFi,而不要使用手机,这样我们就不会浪费用户的手机数据计划。 目前,我们正在使用ConnectionManager检查连接状态,并确保他们已连接到WiFi。这种方法似乎已经停止在Android 7上工作,因为有时即使连接了WiFi,操作系统也会决定通过手机发送请求。 在iOS上,我们可以使用allowscellaracces

  • [编辑:已修复!问题似乎是布局xml中有一个不可见的视频视图覆盖了我的GLSURFACHEVIEW。从布局中删除视频视图将恢复预期的行为。] [编辑#2:使GLSurfaceView使用ARGB888也应该解决这一问题(我认为不能混合具有不同颜色格式的曲面),因为这样做是为了在视频上显示GL。] 我成功地使用了GLSurfaceView,但在Android 3.2平板电脑上发现了一个奇怪的问题。G

  • 我正在搜索am算法来生成一个六边形蜂窝,就像这样使用轴向坐标: 我提出这个问题只是为了分享我的解决方案。

  • 本文向大家介绍python 爬取马蜂窝景点翻页文字评论的实现,包括了python 爬取马蜂窝景点翻页文字评论的实现的使用技巧和注意事项,需要的朋友参考一下 使用Chrome、python3.7、requests库和VSCode进行爬取马蜂窝黄鹤楼的文字评论(http://www.mafengwo.cn/poi/5426285.html)。 首先,我们复制一段评论,查看网页源代码,按Ctrl+F查找