Android系統資訊獲取 之十一:獲取IMEI,IMSI號
阿新 • • 發佈:2019-01-06
對於移動資訊的獲取本不想再寫,只是在開發的過程中還是有同事來討論,因此就單獨再把幾個重要的資訊獲取點給列出來,供查詢使用。
IMEI號,IMSI號的知識點可參考:IMSI號和IMEI解釋
Android系統中IMSI號和IMEI號的獲取一樣可以通過TelephonyManager類來獲取,還有另外一種方式通過Settings.System的ANDROID_ID來獲取,這裡需要注意一下,Android系統裡不少資訊除了通過各種類獲取之外還可以通過Android系統的資料庫,檔案(例如獲取CPU資訊的時候)來獲取。
通過TelephonyManager類來獲取IMSI,IMEI號:
-
public static TelephonyManager getTelephonyManager(Context context) {
- // 獲取telephony系統服務,用於取得SIM卡和網路相關資訊
- if (mTelephonyManager == null) {
- mTelephonyManager = (TelephonyManager) context
- .getSystemService(Context.TELEPHONY_SERVICE);
- }
- return mTelephonyManager;
- }
- /**
-
* 唯一的裝置ID: GSM手機的 IMEI 和 CDMA手機的 MEID. Return null if device ID is not
- * 取得手機IMEI
- * available.
- */
- public static String getDeviceId(Context context) {
- mDeviceId = getTelephonyManager(context).getDeviceId();// String
- return mDeviceId;
- }
- /**
- * 取得IMEI SV
- * 裝置的軟體版本號: 返回移動終端的軟體版本,例如:GSM手機的IMEI/SV碼。 例如:the IMEI/SV(software version)
-
* for GSM phones. Return null if the software version is not available.
- */
- public static String getDeviceSoftwareVersion(Context context) {
- mDeviceSoftwareVersion = getTelephonyManager(context).getDeviceSoftwareVersion();// String
- return mDeviceSoftwareVersion;
- }
- /**
- * 取得手機IMSI
- * 返回使用者唯一標識,比如GSM網路的IMSI編號 唯一的使用者ID: 例如:IMSI(國際移動使用者識別碼) for a GSM phone.
- * 需要許可權:READ_PHONE_STATE
- */
- public static String getSubscriberId(Context context) {
- mSubscriberId = getTelephonyManager(context).getSubscriberId();// String
- return mSubscriberId;
- }
通過Settings.System的ANDROID_ID獲取
- private String getAndroidIMEI(Context context){
- String androidIMEI = android.provider.Settings.System.getString(getContentResolver(context), android.provider.Settings.System.ANDROID_ID);
- Log.d("ANDROID_ID", androidIMEI + " ");
- return androidIMEI;
- }