Getting SIM state and subscribing to SIM state changes

This topic describes how to get SIM state and subscribe to SIM state changes.

Steps

  1. Subscribe to SIMStateListener using SIMState.subscribeListener() method.

    //Sample code to subscribe to SIM state changes
    
    try {
        SIMState.subscribeListener(this);
    }
    catch (Exception e) {
    }
  2. Implement the SIMStateListener interface by defining the SIMStateListener.SIMStateChanged() method.

    // Sample code implementing the SIMStateListener interface
    
    public void SIMStateChanged(int simIndex, int state) {
         form.append("SIM card state on slot " + simIndex + " is " + state);
    }
    
  3. Get the SIM state of the SIM card in the first slot by calling the SIMState.getState() method.

    //Sample code to get the SIM state of the SIM card in the first slot
    
    SIMState.getState(0);