I am working on Android startup, which mainly depends on the state of the SIM card. When my application starts automatically, I need to check it, where the SIM card was changed. After that, I compare the current SIM card with the previous SIM card, getting general preferences. But the application returns a null pointer exception when a new SIM value is received.
I want to respond to sim states.
When I get the SIM_STATE_READY state, I want to get the new SIM status from the phone manager.
telMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); int simState = telMgr.getSimState(); switch (simState) { case (TelephonyManager.SIM_STATE_ABSENT): System.out.println("*******************************************Sim State absent******************************"); break; case (TelephonyManager.SIM_STATE_NETWORK_LOCKED): System.out.println("*******************************************SIM_STATE_NETWORK_LOCKED******************************"+sim); break; case (TelephonyManager.SIM_STATE_PIN_REQUIRED): System.out.println("*******************************************SIM_STATE_PIN_REQUIRED******************************"+sim); break; case (TelephonyManager.SIM_STATE_PUK_REQUIRED): System.out.println("*******************************************SIM_STATE_PUK_REQUIRED******************************"+sim); break; case (TelephonyManager.SIM_STATE_UNKNOWN): System.out.println("*******************************************SIM_STATE_UNKNOWN******************************"+sim); break; case (TelephonyManager.SIM_STATE_READY): { } break; } default: break; }
I do this, but donβt know how to listen to the SIM state that I want when the SIM card is ready so that I can execute some kind of code. When the device boots up, it always returns "SIM_STATE_UNKNOWN" and terminates the program.
Please help me achieve this.
android
vivek_Android
source share