Android 基础信息获取
持续更新中。。。
1、设备信息
手机号
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number()
IMEI(国际移动设备识别码)
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId()
IMSI(国际移动用户识别码)
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId()
SIM(序列号)
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSimSerialNumber()
SimCountryIso(sim卡国家码)
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSimCountryIso()
SimOperatorName(SPN,sim卡运营商名称)
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSimOperatorName()
NetworkCountryIso(网络运营商国家码)
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getNetworkCountryIso()
NetworkOperatorName(网络运营商名称)
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getNetworkOperatorName()
2、网络
网络类型(wifi、2|3|4g)
public static String getNetWorkType(Context context) {
String type = "";
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info == null) {
type = "null";
} else if (info.getType() == ConnectivityManager.TYPE_WIFI) {
type = "wlan";
} else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
int subType = info.getSubtype();
switch (subType) {
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN:
type = "2g";
break;
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_EHRPD:
case TelephonyManager.NETWORK_TYPE_HSPAP:
case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
type = "3g";
break;
case TelephonyManager.NETWORK_TYPE_LTE:
type = "4g";
break;
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
default:
type = "cellular";
break;
}
}
return type;
}
WIFI-SSID(无线网络名称)
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Log.i("NET_CHECK", "wifi - ssid=" + wifiInfo.getSSID());
WIFI-BSSID(无线网络mac地址)
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Log.i("NET_CHECK", "wifi - ssid=" + wifiInfo.getSSID());
WIFI-DNS(无线网络域名服务器)
public String getDNSServers() {
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifiManager == null || !wifiManager.isWifiEnabled()) {
return "";
}
DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();
if (dhcpInfo != null) {
if (dhcpInfo.dns1 != 0) {
return intToIp(dhcpInfo.dns1);
}
if (dhcpInfo.dns2 != 0) {
return intToIp(dhcpInfo.dns2);
}
}
return "";
}
WIFI-信号强度
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Log.i("NET_CHECK", "wifi - wifi_signal=" + WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 100));
数据-CID(基站id)
TelephonyManager telephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
CellLocation cellLocation = telephonyManager.getCellLocation();
Log.i("NET_CHECK", "data - cid=" + ((GsmCellLocation) cellLocation).getCid());
数据-LAC(基站位置区码)
TelephonyManager telephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
CellLocation cellLocation = telephonyManager.getCellLocation();
Log.i("NET_CHECK", "data - lac=" + ((GsmCellLocation) cellLocation).getLac());
数据-MNC(移动网络码)
TelephonyManager telephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Log.i("NET_CHECK", "data - mnc=" + Integer.valueOf(networkOperator.substring(3)).intValue());
数据-MCC(移动国家码)
TelephonyManager telephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Log.i("NET_CHECK", "data - mcc=" + Integer.valueOf(networkOperator.substring(0, 3)).intValue());
数据-BSSS(信号强度)、TAC(运营商跟踪区代码)
TelephonyManager telephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager.getAllCellInfo() == null) {
Log.i("NET_CHECK", "data - getAllCellInfo returned null");
} else {
for (final CellInfo info : telephonyManager.getAllCellInfo()) {
if (info instanceof CellInfoLte) {
CellIdentityLte lte_cell = ((CellInfoLte) info).getCellIdentity();
Log.i("NET_CHECK", "data - bsss=" + ((CellInfoLte) info).getCellSignalStrength());
Log.i("NET_CHECK", "data - tac=" + lte_cell.getTac());
}
}
}