Android如何获取唯一ID
正文
IMEI
概念
摘自維基百科:
國(guó)際移動(dòng)設(shè)備識(shí)別碼(International Mobile Equipment Identity,IMEI),即通常所說(shuō)的手機(jī)序列號(hào)、手機(jī)“串號(hào)”,用于在行動(dòng)電話網(wǎng)絡(luò)中識(shí)別每一部獨(dú)立的手機(jī)等行動(dòng)通訊裝置,相當(dāng)于行動(dòng)電話的身份證。序列號(hào)共有15位數(shù)字,前6位(TAC)是型號(hào)核準(zhǔn)號(hào)碼,代表手機(jī)類型。接著2位(FAC)是最后裝配號(hào),代表產(chǎn)地。后6位(SNR)是串號(hào),代表生產(chǎn)順序號(hào)。最后1位(SP)一般為0,是檢驗(yàn)碼,備用。國(guó)際移動(dòng)設(shè)備識(shí)別碼一般貼于機(jī)身背面與外包裝上,同時(shí)也存在于手機(jī)記憶體中,通過(guò)輸入*#06#即可查詢。
代碼
獲取權(quán)限,修改AndroidManifest.xml。
<uses-permission android:name="android.permission.READ_PHONE_STATE" />樣例代碼,參考這里:
public static String getIMEI(Context context) {String imei = "";try {TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {return imei;}imei = telephonyManager.getDeviceId();if (imei == null && imei.isEmpty()) {return "";}} catch (Exception e) {e.printStackTrace();}return imei; }MAC
概念:
摘自維基百科:
路由器標(biāo)簽上的MAC地址(LAN/WLAN)
MAC地址(英語(yǔ):Media Access Control Address),直譯為媒體訪問(wèn)控制地址,也稱為局域網(wǎng)地址(LAN Address),以太網(wǎng)地址(Ethernet Address)或物理地址(Physical Address),它是一個(gè)用來(lái)確認(rèn)網(wǎng)絡(luò)設(shè)備位置的地址。在OSI模型中,第三層網(wǎng)絡(luò)層負(fù)責(zé)IP地址,第二層數(shù)據(jù)鏈接層則負(fù)責(zé)MAC地址。MAC地址用于在網(wǎng)絡(luò)中唯一標(biāo)示一個(gè)網(wǎng)卡,一臺(tái)設(shè)備若有一或多個(gè)網(wǎng)卡,則每個(gè)網(wǎng)卡都需要并會(huì)有一個(gè)唯一的MAC地址。
代碼:
獲取權(quán)限:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>樣例代碼,參考這里:
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); WifiInfo wInfo = wifiManager.getConnectionInfo(); String macAddress = wInfo.getMacAddress();SSN(sim卡序列號(hào))
概念:
摘自這里:
Your SIM serial number (SSN), sometimes called the ICC-ID (Integrated Circuit Card ID), is for international identification. The SNN typically has 19 digits and contains specific details about your operator, your location, and when it was made. The first two digits are the telecom ID, the second two digit refer to your country code, the third two digits are the network code, the next four digits are the month and year of manufacturing, the next two digits are the switch configuration code, the next six digits are the SIM number, and the last digit is the check digit.
簡(jiǎn)單翻譯:SIM 序列號(hào),有的時(shí)候又被成為ICC-ID(集成電路卡ID),典型的SSN是由19位數(shù)字組成的,包含一些運(yùn)行商、位置信息等。代碼:
獲取權(quán)限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>樣例代碼:
public static String getSimId (Context context) {TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);String SimSerialNumber = tm.getSimSerialNumber();return SimSerialNumber; }IMSI
概念:
摘自這里:
The international mobile subscriber identity or IMSI /??mzi?/ is used to identify the user of a cellular network and is a unique identification associated with all cellular networks. It is stored as a 64 bit field and is sent by the phone to the network. It is also used for acquiring other details of the mobile in the home location register (HLR) or as locally copied in the visitor location register. To prevent eavesdroppers identifying and tracking the subscriber on the radio interface, the IMSI is sent as rarely as possible and a randomly generated TMSI is sent instead.
簡(jiǎn)單翻譯:IMSI,國(guó)際移動(dòng)訂戶標(biāo)識(shí),用于標(biāo)識(shí)移動(dòng)網(wǎng)絡(luò)的用戶,是移動(dòng)網(wǎng)絡(luò)的一個(gè)唯一的標(biāo)識(shí)。它保存為一個(gè)64位的域,由手機(jī)發(fā)給網(wǎng)絡(luò)。
代碼:
獲取權(quán)限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>樣例代碼,參考這里:
String IMSI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI); //這種方法還沒有確認(rèn)過(guò),看帖子上說(shuō),這個(gè)代碼google沒有暴露出來(lái),需要通過(guò)一些技巧去使用另外一個(gè)樣例:
private static String getIMSI(Context context) {String imsi = "";try {TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {return imsi;}imsi = telephonyManager.getSubscriberId();if (TextUtils.isEmpty(imsi) || IMSI == imsi) {return imsi;}return imsi;} catch (Exception e) {e.printStackTrace();}return imsi;}ANDROIDID - 安卓ID
概念:
參考這里:
On Android 8.0 (API level 26) and higher versions of the platform, a 64-bit number (expressed as a hexadecimal string), unique to each combination of app-signing key, user, and device. Values of ANDROID_ID are scoped by signing key and user. The value may change if a factory reset is performed on the device or if an APK signing key changes. For more information about how the platform handles ANDROID_ID in Android 8.0 (API level 26) and higher, see Android 8.0
簡(jiǎn)單翻譯:Android8和更過(guò)版本,提供了一個(gè)64位的標(biāo)識(shí)符,對(duì)于app簽名的key、用戶和設(shè)備是唯一的。
代碼:
獲取權(quán)限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />樣例代碼:
public static String getAndroidId (Context context) {String androidId = Settings.System.getString(context.getContentResolver(), Settings.System.ANDROID_ID);return androidId; }Serial Number
概念
參考這里:
A hardware serial number, if available. Alphanumeric only, case-insensitive. For apps targeting SDK higher than Build.VERSION_CODES.O_MR1 this field is set to UNKNOWN.
簡(jiǎn)單翻譯:硬件序列號(hào)。
代碼:
獲取權(quán)限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />樣例代碼
public static String getSerialNumber (Context context) {String SerialNumber = android.os.Build.getSerial();return SerialNumber; }參考
https://blog.csdn.net/jiangtea/article/details/72889018,這個(gè)帖子整理得挺好。
https://blog.csdn.net/aa1733519509/article/details/50053553,這里面有一些樣例代碼。
總結(jié)
以上是生活随笔為你收集整理的Android如何获取唯一ID的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: JAVA NIO 实现群聊
- 下一篇: android view分析工具,And