public String getSubscriberId(){
operator = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String IMSI = operator.getSubscriberId();
return IMSI;
}
simID = (TextView) findViewById(R.id.text2);
simIMSI = getSubscriberId().toString();
if (simIMSI.equals("")){
simID.setText("No SIM card detected!");
}
else{
simID.setText(simIMSI.toString());
SaveUniqueId(simIMSI.toString());
}
我希望检索手机SIM卡IMSI并在布局中显示,我使用仿真器运行程序,即使我知道仿真器没有连接SIM卡,但它应该有类似“没有检测到SIM卡”的结果,对吗?但是为什么我的代码会出错,或者是我的"getSubscriberId()“出了什么问题?
发布于 2012-05-21 16:58:19
String serviceName = Context.TELEPHONY_SERVICE;
TelephonyManager m_telephonyManager = (TelephonyManager) getSystemService(serviceName);
现在让我们从检索信息的实际源代码开始:
public String findDeviceID() {
String deviceID = null;
String serviceName = Context.TELEPHONY_SERVICE;
TelephonyManager m_telephonyManager = (TelephonyManager) getSystemService(serviceName);
int deviceType = m_telephonyManager.getPhoneType();
switch (deviceType) {
case (TelephonyManager.PHONE_TYPE_GSM):
break;
case (TelephonyManager.PHONE_TYPE_CDMA):
break;
case (TelephonyManager.PHONE_TYPE_NONE):
break;
default:
break;
}
deviceID = m_telephonyManager.getDeviceId();
return deviceID;
}
有关更多详细信息,请参阅此站点http://ashnatechnologies.blogspot.in/2010/10/how-to-get-imei-on-android-devices.html
发布于 2012-05-21 16:55:38
您可以访问此链接http://www.anddev.org/tinytut_-_getting_the_imsi_-_imei_sim-device_unique_ids-t446.html
对IMSI使用以下代码
String imsi = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);
发布于 2013-06-25 15:25:57
这段代码应该可以工作。
String myIMSI =
android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);
https://stackoverflow.com/questions/10682124
复制相似问题