Android(安卓)获取基站信息
16lz
2021-12-04
Android 基站分CdmaCellLocation和GsmCellLocation,要根据不同的SIM卡转成不同的对象
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int type = tm.getNetworkType();//获取网络类型
//在中国,移动的2G是EGDE,联通的2G为GPRS,电信的2G为CDMA,电信的3G为EVDO
Location loc = null;
ArrayList CellID = new ArrayList();
//中国电信为CTC
//NETWORK_TYPE_EVDO_A是中国电信3G的getNetworkType
//NETWORK_TYPE_CDMA电信2G是CDMA
if (type == TelephonyManager.NETWORK_TYPE_EVDO_A || type == TelephonyManager.NETWORK_TYPE_CDMA || type ==TelephonyManager.NETWORK_TYPE_1xRTT)
{
location = (CdmaCellLocation) tm.getCellLocation();
if(location == null)
throw new Exception("errr");
String operator = tm.getNetworkOperator();
int cellIDs = location.getBaseStationId();
int networkID = location.getNetworkId();
StringBuilder sb = new StringBuilder();
sb.append(location.getSystemId());
int mnc = Integer.parseInt(nsb.toString());
int mcc = Integer.parseInt(operator.substring(0,3));
}
//移动2G卡 + CMCC + 2
//type = NETWORK_TYPE_EDGE
//联通的2G经过测试 China Unicom 1 NETWORK_TYPE_GPRS
else if(type == TelephonyManager.NETWORK_TYPE_EDGE || type == TelephonyManager.NETWORK_TYPE_GPRS)
{
GsmCellLocation location = (GsmCellLocation)tm.getCellLocation();
location = (CdmaCellLocation) tm.getCellLocation();
if(location == null)
throw new Exception("errr");
String operator = tm.getNetworkOperator();
int mcc = Integer.parseInt(operator.substring(0,3));
int mnc = Integer.parseInt(operator.substring(3));
int cid = location.getCid();
int lac = location.getLac();
}
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int type = tm.getNetworkType();//获取网络类型
//在中国,移动的2G是EGDE,联通的2G为GPRS,电信的2G为CDMA,电信的3G为EVDO
Location loc = null;
ArrayList CellID = new ArrayList();
//中国电信为CTC
//NETWORK_TYPE_EVDO_A是中国电信3G的getNetworkType
//NETWORK_TYPE_CDMA电信2G是CDMA
if (type == TelephonyManager.NETWORK_TYPE_EVDO_A || type == TelephonyManager.NETWORK_TYPE_CDMA || type ==TelephonyManager.NETWORK_TYPE_1xRTT)
{
location = (CdmaCellLocation) tm.getCellLocation();
if(location == null)
throw new Exception("errr");
String operator = tm.getNetworkOperator();
int cellIDs = location.getBaseStationId();
int networkID = location.getNetworkId();
StringBuilder sb = new StringBuilder();
sb.append(location.getSystemId());
int mnc = Integer.parseInt(nsb.toString());
int mcc = Integer.parseInt(operator.substring(0,3));
}
//移动2G卡 + CMCC + 2
//type = NETWORK_TYPE_EDGE
//联通的2G经过测试 China Unicom 1 NETWORK_TYPE_GPRS
else if(type == TelephonyManager.NETWORK_TYPE_EDGE || type == TelephonyManager.NETWORK_TYPE_GPRS)
{
GsmCellLocation location = (GsmCellLocation)tm.getCellLocation();
location = (CdmaCellLocation) tm.getCellLocation();
if(location == null)
throw new Exception("errr");
String operator = tm.getNetworkOperator();
int mcc = Integer.parseInt(operator.substring(0,3));
int mnc = Integer.parseInt(operator.substring(3));
int cid = location.getCid();
int lac = location.getLac();
}
更多相关文章
- android通过代码来开启和关闭移动网络
- Android的联通性---USB的从属模式(一)
- 【原创】Android(安卓)耗电信息统计服务——BatteryStats源码分
- 【Android】联通性 -- USB从属模式
- 【Android】联通性 -- USB从属模式
- 中国电信已加盟Android阵营
- Google放弃“不做恶”? 意欲垄断Android
- android 获取网络类型名称2G 3G 4G wifi
- 电信大宽带服务器300M谁家有?