I have written an android app which listens to the phone signal
strength. The app works perfectly with Android 1.6 and lower using
PhoneStateListener.SignalStrengthChanged(int asu), but I can't get it
to work on Android 2.1.

I know that I have to use onSignalStrengthsChanged(SignalStrength
signalStrength) but this override never seems to be called in my code.
SignalStrengthChanged(int asu) is called, 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 anyone know what I'm doing wrong?

I'm testing on a EVO with Android 2.1. The phone type
(TelephonyManager.getPhoneType) is CDMA and
TelephonyManager.getNetworkType returns "EVDO_A".

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.");  // this never gets called

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


Thanks in advance

TAO

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to