What is the best way to print signal strength in Android Studio?

322 Views Asked by At

How do I get the signal strength in the other class to print out on the emulator screen. I have used most of this code from other code found on stack overflow. I have a class where I calculate mSignalStrength and this is the value I would liek to be able to print in my main activity class which has the onCreate method. This is what I have so far:

   protected void onCreate(Bundle savedInstanceState) { TelephonyManager mTelephonyManager;
    MyPhoneStateListener mPhoneStatelistener;
    mPhoneStatelistener = new MyPhoneStateListener();
    mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mTelephonyManager.listen(mPhoneStatelistener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    setContentView(R.layout.fragment_gallery);
    TextView textView = (TextView) findViewById(R.id.text_gallery);
    String message = "The Signal Strength is ";
    textView.setText(message);}

     public class MyPhoneStateListener extends PhoneStateListener {

public void onSignalStrengthsChanged(SignalStrength signalStrength) {
    int mSignalStrength = signalStrength.getGsmSignalStrength();
    mSignalStrength = (2 * mSignalStrength) - 113; // -> dBm
    Globals textSignalStrength = Globals.getInstance();
    textSignalStrength.setTxtSignalStr(Integer.toString(mSignalStrength));
}

}

0

There are 0 best solutions below