public String readSIMCard() {
TelephonyManager tm = (TelephonyManager)this.getSystemService(TELEPHONY_SERVICE);//取得相關系統服務
StringBuffer sb = new StringBuffer();
switch(tm.getSimState()){ //getSimState()取得sim的狀態 有下面6中狀態
case TelephonyManager.SIM_STATE_ABSENT :sb.append("無卡");break;
case TelephonyManager.SIM_STATE_UNKNOWN :sb.append("未知狀態");break;
case TelephonyManager.SIM_STATE_NETWORK_LOCKED :sb.append("需要NetworkPIN解鎖");break;
case TelephonyManager.SIM_STATE_PIN_REQUIRED :sb.append("需要PIN解鎖");break;
case TelephonyManager.SIM_STATE_PUK_REQUIRED :sb.append("需要PUK解鎖");break;
case TelephonyManager.SIM_STATE_READY :sb.append("良好");break;
}
if(tm.getSimSerialNumber()!=null){
sb.append("@" + tm.getSimSerialNumber().toString());
}else{
sb.append("@無法取得SIM卡號");
}
if(tm.getSimOperator().equals("")){
sb.append("@無法取得供貨商代碼");
}else{
sb.append("@" + tm.getSimOperator().toString());
}
if(tm.getSimOperatorName().equals("")){
sb.append("@無法取得供貨商");
}else{
sb.append("@" + tm.getSimOperatorName().toString());
}
if(tm.getSimCountryIso().equals("")){
sb.append("@無法取得國籍");
}else{
sb.append("@" + tm.getSimCountryIso().toString());
}
if (tm.getNetworkOperator().equals("")) {
sb.append("@無法取得網絡運營商");
} else {
sb.append("@" + tm.getNetworkOperator());
}
if (tm.getNetworkOperatorName().equals("")) {
sb.append("@無法取得網絡運營商名稱");
} else {
sb.append("@" + tm.getNetworkOperatorName());
}
if (tm.getNetworkType() == 0) {
sb.append("@無法取得網絡類型");
} else {
sb.append("@" + tm.getNetworkType());
}
return sb.toString();
}