Search code examples
androidandroid-2.3-gingerbread

Android Network Provider RSSI: displaying the dBm in textview


I'm trying to display the dBm just as you can see it under:

Settings>About Phone>Status ..

so far I have gotten to the point of the app not crashing on me.

It now, just doesn't display anything in the textview.

I've looked at a lot of post's on here and each one, is something different then what I am looking for. Thought it would be a simple search and find, turns out that its not.

Not sure what I'm doing wrong here, no errors in LogCat anyone has any ideas that would be awesome.

the developer references don't help me at all, unless it has something showing me how it is use/working so I can understand it. I've tried and failed lol, anyway heres my code:

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.widget.TextView;

public class Screen extends Activity {

    TextView dbm;
    String dBm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainfull);
        dbm = (TextView) findViewById(R.id.Signal);

        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        List<NeighboringCellInfo> NeighboringList = telephonyManager
                .getNeighboringCellInfo();

        for (int i = 0; i < NeighboringList.size(); i++) {

            int rssi = NeighboringList.get(i).getRssi();

            if (rssi == NeighboringCellInfo.UNKNOWN_RSSI) {
                dBm = "Unknown RSSI";
            } else {
                dBm = String.valueOf(-113 + 2 * rssi) + " dBm";
            }

        }

        dbm.setText(dBm);

    }
}

not sure if I'm missing any info that might be helpful, if so let me know


Solution

  • Perhaps NeighboringList is empty?

    Do you really want the RSSI of the neighboring cells or of the current cell? To get the RSSI of the current cell, you can register this listener:

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