Android 基礎(chǔ)信息獲取
持續(xù)更新中。。。
1、設(shè)備信息
手機號
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number()
IMEI(國際移動設(shè)備識別碼)
((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(網(wǎng)絡(luò)運營商國家碼)
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getNetworkCountryIso()
NetworkOperatorName(網(wǎng)絡(luò)運營商名稱)
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getNetworkOperatorName()
2、網(wǎng)絡(luò)
網(wǎng)絡(luò)類型(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(無線網(wǎng)絡(luò)名稱)
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Log.i("NET_CHECK", "wifi - ssid=" + wifiInfo.getSSID());
WIFI-BSSID(無線網(wǎng)絡(luò)mac地址)
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Log.i("NET_CHECK", "wifi - ssid=" + wifiInfo.getSSID());
WIFI-DNS(無線網(wǎng)絡(luò)域名服務(wù)器)
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));
數(shù)據(jù)-CID(基站id)
TelephonyManager telephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
CellLocation cellLocation = telephonyManager.getCellLocation();
Log.i("NET_CHECK", "data - cid=" + ((GsmCellLocation) cellLocation).getCid());
數(shù)據(jù)-LAC(基站位置區(qū)碼)
TelephonyManager telephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
CellLocation cellLocation = telephonyManager.getCellLocation();
Log.i("NET_CHECK", "data - lac=" + ((GsmCellLocation) cellLocation).getLac());
數(shù)據(jù)-MNC(移動網(wǎng)絡(luò)碼)
TelephonyManager telephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Log.i("NET_CHECK", "data - mnc=" + Integer.valueOf(networkOperator.substring(3)).intValue());
數(shù)據(jù)-MCC(移動國家碼)
TelephonyManager telephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Log.i("NET_CHECK", "data - mcc=" + Integer.valueOf(networkOperator.substring(0, 3)).intValue());
數(shù)據(jù)-BSSS(信號強度)、TAC(運營商跟蹤區(qū)代碼)
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());
}
}
}