android 获取IMSI

隗高旻
2023-12-01
The following code is deprecated.

String myIMSI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);
// within my emulator it returns: 310995000000000

String myIMEI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMEI);
// within my emulator it returns: 000000000000000

In order to get IMSI and IMEI, the following code works, assuming you write the code in a Activity class.

TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imsi = mTelephonyMgr.getSubscriberId();
String imei = mTelephonyMgr.getDeviceId();

Do not forget to set <uses-permission android:name="android.permission.READ_PHONE_STATE"/> in AndroidManifest.xml.

 类似资料: