Getting network state of a SIM card and subscribing to network state changes

This topic describes how to get network state of a SIM card and subscribe to network state changes.

Steps

  1. Subscribe to NetworkStateListener using NetworkState.subscribeListener() method.

    //Sample code to subscribe to network state changes
    
    try {
        NetworkState.subscribeListener(this);
    }
    catch (Exception e) {
    }
  2. Implement the NetworkStateListener interface by defining the NetworkStateListener.networkStateChanged() method.

    // Sample code implementing the NetworkStateListener interface
    
    public void networkStateChanged(int simIndex, int state) {
         form.append("Received  network state on SIM slot " + simIndex + " state is " + state);
    }
    
  3. Get the network state of the SIM card in the second slot by calling the NetworkState.getState() method.

    //Sample code to get the network state of the SIM card in the second slot
    NetworkState.getState(1);