2012-05-21 63 views
2
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()」中出現錯誤?如何在Android中檢索SIM卡IMSI?

+0

檢查這個問題:http://stackoverflow.com/questions/6033511/get-imei-code-or-and-mac-address-of-a-device – thepoosh

+0

什麼是你的錯誤? –

回答

3
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

0

此代碼應該工作。

String myIMSI = 
android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);