This topic describes how to get network state of a SIM card and subscribe to network state changes.
Subscribe
to NetworkStateListener
using NetworkState.subscribeListener()
method.
//Sample code to subscribe to network state changes try { NetworkState.subscribeListener(this); } catch (Exception e) { }
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); }
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);