我能够使用telephonymanager获得sim卡的序列号,代码正常工作。但是,如果没有插入SIM卡,它会关闭,那么有什么办法来处理这个异常?使用telephonymanager获取sim序列号
private void getAndSaveCurrentID(View view) {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// ---get first time SIM card ID ---
String simID = tm.getSimSerialNumber();
if (simID != null)
Toast.makeText(this, "current SIM card ID: saved " + simID,
Toast.LENGTH_LONG).show();
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Name", simID.toString());
editor.commit();
}
02-14 11:27:42.643: E/AndroidRuntime(9674): FATAL EXCEPTION: main
02-14 11:27:42.643: E/AndroidRuntime(9674): Process: com.air.bgusatm, PID: 9674
02-14 11:27:42.643: E/AndroidRuntime(9674): java.lang.IllegalStateException: Could not find a method getAndSaveCurrentID(View) in the activity class com.air.bgusatm.MainActivity for onClick handler on view class android.widget.Button with id 'button1'
它会工作,如果我围绕它与一个尝试缓存块?
SIMID不能被解析为一个变量 – Felicia
TM解决不了 – Felicia
其投掷空当它不具有SIM卡 – dileep