获得信号强度

时间:2012-05-10 03:40:28

标签: java android telephony signal-strength

我想知道如何使用Android获得CDMA / GSM信号强度。

注意:我使用了getCdmaDbm()方法,但它总是返回-1。

1 个答案:

答案 0 :(得分:1)

使用PhoneStateListener的onSignalStrengthsChanged获取SignalStrength:

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(srvcName);  
AndroidPhoneStateListener phoneStateListener = new AndroidPhoneStateListener (this);  
telephonyManager.listen(phoneStateListener,      
PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    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();
            }
        }

    }

许可:

<uses-permission Android:name="android.permission.READ_PHONE_STATE" />