Reputation: 1
How do I detect when the GSM signal strength is low and the cellular network is lost? What about dual SIM devices?
Upvotes: 0
Views: 2084
Reputation: 14093
Android: how to detect “no carrier” SIM card mode ?
The PhoneStateListener
class is designed to serve this purpose. When using it, you can get callbacks when the GSM signal bound to your current provider is changing.
Make sure you have the following android.intent.action.PHONE_STATE
set in your manifest file.
Next, you'll need to invoke the TelephonyManager
and bind your PhoneStateListener
to it :
TelephonyManager telManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
telManager.listen(this.phoneListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
You can implement your PhoneStateListener
as such :
private final PhoneStateListener phoneListener = new PhoneStateListener() {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
Log.d("onSignalStrengthsChanged", "The new singal strength is "
+ signalStrength.getGsmSignalStrength());
}
};
GSM signal strengths values are defined in TS 27.007 8.5
. Basically a value of 0 is low, a value of 31 is good, and a value of 99 means not known or not detectable. Valid values are (0-31, 99) as stated in the Android Developers manual.
The above covers GSM signals, so if you are only interested in GSM signals, stick to my previous example. If you might be interested in stating whether a data network is available or not due to a lack of signal strength, you can also get other signal values for all the available data networks :
You can know what is the type of the current data network by calling the TelephonyManager.getNetworkType()
method.
What about dual SIM devices ?
I don't know, never worked on them. However I don't see why the above may not be applicable to multi-SIM devices. It should be working as such.
Upvotes: 3