Problem with PhoneStateListener.onSignalStrengthsChanged


Last Updated:

  1. TheArchedOne

    TheArchedOne New Member This Topic's Starter

    Joined:
    Jul 6, 2010
    Messages:
    4
    Likes Received:
    0
    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 anyone know what I'm doing wrong?
    Here's the code:
    Code (Text):
    1. mSignalListener = new PhoneStateListener(){
    2.   @Override
    3.     public void onSignalStrengthChanged(int asu){
    4.       Log.d(Utils.LOGTAG, "#1. " + String.valueOf(asu));
    5.       if (mStrength != asu){
    6.         mStrength = asu;
    7.         NotifyUI();
    8.       }
    9.       super.onSignalStrengthChanged(asu);
    10.     }
    11.  
    12.   @Override
    13.   public void onSignalStrengthsChanged(SignalStrength signalStrength) {
    14.     Log.d(Utils.LOGTAG, "#2.");
    15.  
    16.     if (signalStrength.isGsm())
    17.       mStrength = signalStrength.getGsmSignalStrength();
    18.     else{
    19.       int strength = -1;
    20.       if (signalStrength.getEvdoDbm() < 0)
    21.         strength = signalStrength.getEvdoDbm();
    22.       else if (signalStrength.getCdmaDbm() < 0)
    23.         strength = signalStrength.getCdmaDbm();
    24.  
    25.       if (strength < 0){
    26.         // convert to asu
    27.         mStrength = Math.round((strength + 113f) / 2f);
    28.       }
    29.  
    30.       NotifyUI();
    31.     }              
    32.     super.onSignalStrengthsChanged(signalStrength);
    33.   }
    34. };
    Many thanks in advance.

    TAO
     

    Advertisement

Share This Page

Loading...