0

Hey I tried for signalStrength.getGsmSignalStrength() for GSM and CDMA devices but I noticed that both the devices gives strength even when sim is not inserted in device.I want to place a call or send message only if network is good how can I achieve this? And also want to know which signal strength this API returns!!... Please reply as soon as possible.

public class AndroidPhoneStateListener extends PhoneStateListener {
    public static int signalStrengthValue;

    @Override
    public void onSignalStrengthsChanged(SignalStrength signalStrength) {
        super.onSignalStrengthsChanged(signalStrength);
        if (signalStrength.isGsm()) {
            if (signalStrength.getGsmSignalStrength() != 99)
                signalStrengthValue = signalStrength.getGsmSignalStrength() * 2 - 113;
            else
                signalStrengthValue = signalStrength.getGsmSignalStrength();
        } else {
            signalStrengthValue = signalStrength.getCdmaDbm();
        }
    }

}
JAPS
  • 250
  • 4
  • 15
  • the reason its still showing signal strength might be because the phone still bale to place rescue calls (911) even without sim card – waqaslam Feb 27 '12 at 07:26
  • But why do we require signal strength for rescue calls? Is there any hardware item which gives this response even Sim is not present? – JAPS Feb 27 '12 at 08:14
  • 1
    even there's no sim but still the radio is inside the phone, rite? check my answer to detect if sim card is available or not, afterwards you may calculate the strength for further actions – waqaslam Feb 27 '12 at 08:19

2 Answers2

6

i believe this may help you to detect Sim card availability:

TelephonyManager m = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
if (m.getSimState() != TelephonyManager.SIM_STATE_ABSENT){
  // SIM card
} else {
  // No SIM card
}

moreover, you may read this

Community
  • 1
  • 1
waqaslam
  • 67,549
  • 16
  • 165
  • 178
2

Your phone connects to the cellular network even when you don't have a SIM inserted, provided airplane mode is off, so that emergency calls can be made. Cell operators are required by law to allow such calls. So they allow phones without SIM to register on their network and your phone goes in Emergency Calls Only mode. That's why you read signal strength values with no SIM.

A.J.
  • 1,520
  • 17
  • 22