同一张卡的网络信号,有2G,3G,4G,5G等多种
这里主要实现4G和5G信号强度的获取,2G和3G的获取方式雷同文章来源:https://www.toymoban.com/news/detail-515804.html
但由于现在已经不常用了,所以不再写多余的代码文章来源地址https://www.toymoban.com/news/detail-515804.html
package com.android.architecture;
import android.content.Context;
import android.telephony.CellIdentityLte;
import android.telephony.CellIdentityNr;
import android.telephony.CellInfo;
import android.telephony.CellInfoLte;
import android.telephony.CellInfoNr;
import android.telephony.CellSignalStrengthLte;
import android.telephony.CellSignalStrengthNr;
import android.telephony.TelephonyManager;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("all")
public class SimInfo {
public String operatorCode;
public String operatorName;
public int signalLevel;
public String signalLevelName;
@Override
public String toString() {
return operatorName + " : " + signalLevelName;
}
public void setOperatorName() {
if (operatorCode.equals("46000"))
operatorName = "中国移动";
else if (operatorCode.equals("46002"))
operatorName = "中国移动";
else if (operatorCode.equals("46004"))
operatorName = "中国移动";
else if (operatorCode.equals("46007"))
operatorName = "中国移动";
else if (operatorCode.equals("46008"))
operatorName = "中国移动";
else if (operatorCode.equals("46003"))
operatorName = "中国电信";
else if (operatorCode.equals("46005"))
operatorName = "中国电信";
else if (operatorCode.equals("46011"))
operatorName = "中国电信";
else if (operatorCode.equals("46001"))
operatorName = "中国联通";
else if (operatorCode.equals("46006"))
operatorName = "中国联通";
else if (operatorCode.equals("46009"))
operatorName = "中国联通";
else if (operatorCode.equals("46020"))
operatorName = "中国铁通";
else
operatorName = "其它运营商";
}
public void setSignalLevelName() {
if (signalLevel == 4)
signalLevelName = "好";
else if (signalLevel == 3)
signalLevelName = "中";
else if (signalLevel == 2)
signalLevelName = "差";
else if (signalLevel == 1)
signalLevelName = "极差";
else
signalLevelName = "无信号";
}
//获取所有SIM卡的信号强度信息
public static List<SimInfo> getAllSimInfo(Context context) {
TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class);
List<SimInfo> simInfoList = new ArrayList();
List<CellInfo> cellInfoList = telephonyManager.getAllCellInfo();
for (CellInfo cellInfo : cellInfoList) {
if (!cellInfo.isRegistered())
continue;
//4G
if (cellInfo instanceof CellInfoLte) {
CellInfoLte lte = (CellInfoLte) cellInfo;
CellIdentityLte identity = lte.getCellIdentity();
CellSignalStrengthLte strength = lte.getCellSignalStrength();
SimInfo simInfo = new SimInfo();
simInfo.operatorCode = identity.getMobileNetworkOperator();
simInfo.signalLevel = strength.getLevel();
simInfo.setOperatorName();
simInfo.setSignalLevelName();
simInfoList.add(simInfo);
}
//5G
if (cellInfo instanceof CellInfoNr) {
CellInfoNr nr = (CellInfoNr) cellInfo;
CellIdentityNr identity = (CellIdentityNr) nr.getCellIdentity();
CellSignalStrengthNr strength = (CellSignalStrengthNr) nr.getCellSignalStrength();
SimInfo simInfo = new SimInfo();
simInfo.operatorCode = "" + identity.getMccString() + identity.getMncString();
simInfo.signalLevel = strength.getLevel();
simInfo.setOperatorName();
simInfo.setSignalLevelName();
simInfoList.add(simInfo);
}
}
return simInfoList;
}
}
到了这里,关于【Android】获取手机上所有电话卡的运营商和信号强度的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!