我已经编写了一个Android应用程序,它使用PhoneStateListener.SignalStrengthChanged(int asu)来监听手机信号强度。该应用程序与Android 1.6及更低版本完美配合,但由于onSignalStrengthChanged(int asu)已被弃用并替换为onSignalStrengthsChanged(SignalStrength signalStrength),因此不适用于更高版本。
为了使应用程序与Android 2.0及更高版本兼容,我已将应用程序升级为使用2.1 API并覆盖PhoneStateListener.onSignalStrengthsChanged(SignalStrength signalStrength)。我正在使用Android 2.1测试EVO。电话类型(TelephonyManager.getPhoneType)是CDMA,TelephonyManager.getNetworkType返回“EVDO_A”。在此设置中,从不调用onSignalStrengthsChanged(SignalStrength signalStrength),但SignalStrengthChanged(int asu)是,但是这总是返回-1 asu的信号强度,因为它已被取消。我需要让onSignalStrengthsChanged(SignalStrength signalStrength)工作....有谁知道我做错了什么?
以下是代码:
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);
答案 0 :(得分:3)
我想你只是为PhoneStateListener.LISTEN_SIGNAL_STRENGTHS注册了mSignalListener? ((: