-->

signalStrength.getGsmSignalStrength() is giving va

2019-09-02 00:57发布

问题:

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();
        }
    }

}

回答1:

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



回答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.