2

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

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

4

1 回答 1

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" />
于 2012-05-10T03:46:16.990 回答