AndroidVersion11force3G,4GOnlyNetworkRadioinfoSetting
创始人
2024-08-22 00:30:06
0

在Android 11的版本中,可以通过代码实现强制设置3G、4G网络为Only模式。

首先需要在AndroidManifest.xml文件中添加以下权限:

然后可以使用下面的代码段来实现该功能:

//获取Phone对象 TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); //设置网络制式的Type int networkType = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { networkType = TelephonyManager.NETWORK_TYPE_NR;//5G }else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ networkType = TelephonyManager.NETWORK_TYPE_LTE;//4G }else{ networkType = TelephonyManager.NETWORK_TYPE_UMTS;//3G } //设置强制网络模式 if (telephonyManager != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { telephonyManager.setDataNetworkType(TelephonyManager.NETWORK_TYPE_NR_ONLY); }else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { telephonyManager.setPreferredNetworkType(TelephonyManager.NETWORK_TYPE_LTE_ONLY); }else{ try { Class telephonyClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyClass.getDeclaredMethod("getITelephony"); getITelephonyMethod.setAccessible(true); Object ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); Class ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); Method setPreferredNetworkTypeMethod = ITelephonyClass.getDeclaredMethod("setPreferredNetworkType", int.class); setPreferredNetworkTypeMethod.setAccessible(true); setPreferredNetworkTypeMethod.invoke(ITelephonyStub, networkType); } catch (Exception e) { e.printStackTrace(); } } }

这个代码段将在您的应用程序中强制将网络模式设置为

相关内容

热门资讯

解密透视!约局吧德州可以透视吗... 解密透视!约局吧德州可以透视吗!确实真的是有辅助工具(有挂讲解)-哔哩哔哩亲,关键说明,约局吧德州可...
普及透视!we-poker辅助... 普及透视!we-poker辅助软件教程,aapoker能控制牌吗,模块教程(有挂攻略)-哔哩哔哩1、...
科普透视!pokemomo辅助... 科普透视!pokemomo辅助软件!好像存在有辅助神器(讲解有挂)-哔哩哔哩1、pokemomo辅助...
专业透视!wpk插件,wepo... 专业透视!wpk插件,wepoker透视挂底牌,法子教程(有挂教学)-哔哩哔哩1、完成wepoker...
教你透视!福建大菠萝万能辅助器... 教你透视!福建大菠萝万能辅助器!好像有辅助工具(有挂详细)-哔哩哔哩1、上手简单,内置详细流程视频教...
解迷透视!哈糖大菠萝有挂吗5个... 解迷透视!哈糖大菠萝有挂吗5个常用方法,wepoker看底牌,指引教程(有挂规律)-哔哩哔哩1、解迷...
有挂透视!拱趴大菠萝挂!一直是... 有挂透视!拱趴大菠萝挂!一直是真的有辅助脚本(确实有挂)-哔哩哔哩一、拱趴大菠萝挂可以开透视的定义与...
必备透视!pokemmo脚本辅... 必备透视!pokemmo脚本辅助,hhpoker德州透视挂,法子教程(有挂透视)-哔哩哔哩1、该软件...
揭露透视!pokerworld... 揭露透视!pokerworld辅助器!总是是有辅助软件(详细教程)-哔哩哔哩1、用户打开应用后不用登...
普及透视!hhpoker辅助,... 普及透视!hhpoker辅助,wepoker好友房开挂,学习教程(有挂分析)-哔哩哔哩1、wepok...