Problem with PhoneStateListener.onSignalStrengthsChanged
I have written an android app which listens to the phone signal strength using PhoneStateListener.SignalStrengthChanged(int asu). The app works perfectly with Android 1.6 and lower, but not with higher versions since onSignalStrengthChanged(int asu) has been deprecated and replaced with onSignalStrengthsChanged(SignalStrength signalStrength).
To make the app compatible with Android 2.0 and above, I have upgraded the app to use the 2.1 API and overridden PhoneStateListener.onSignalStrengthsChanged(SignalStrength signalStrength). I'm testing on a EVO with Android 2.1. The phone type (TelephonyManager.getPhoneType) is CDMA and TelephonyManager.getNetworkType returns "EVDO_A". On this setup, onSignalStrengthsChanged(SignalStrength signalStrength) is never called, but SignalStrengthChanged(int asu) is, but this always returns a signal strength of -1 asu because its been depecated. I need to get the onSignalStrengthsChanged(SignalStrength signalStrength) to work.... does开发者_如何学Go anyone know what I'm doing wrong?
Here's the code:
mSignalListener = new PhoneStateListener(){
@Override
public void onSignalStrengthChanged(int asu){
Log.d(Utils.LOGTAG, "#1. " + String.valueOf(asu));
if (mStrength != asu){
mStrength = asu;
NotifyUI();
}
super.onSignalStrengthChanged(asu);
}
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
Log.d(Utils.LOGTAG, "#2.");
if (signalStrength.isGsm())
mStrength = signalStrength.getGsmSignalStrength();
else{
int strength = -1;
if (signalStrength.getEvdoDbm() < 0)
strength = signalStrength.getEvdoDbm();
else if (signalStrength.getCdmaDbm() < 0)
strength = signalStrength.getCdmaDbm();
if (strength < 0){
// convert to asu
mStrength = Math.round((strength + 113f) / 2f);
}
NotifyUI();
}
super.onSignalStrengthsChanged(signalStrength);
}
};
mTelManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
mTelManager.listen(mSignalListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTH);
I suppose you just register the mSignalListener for PhoneStateListener.LISTEN_SIGNAL_STRENGTHS as well? ((:
精彩评论