0

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

}

code2315
  • 11
  • 1
  • Duplicate of https://stackoverflow.com/q/58665798/9882579 – MohanKumar Nov 02 '19 at 17:04
  • Does this answer your question? [What is the best way to find and print signal strength of a cell phone in android studio?](https://stackoverflow.com/questions/58665798/what-is-the-best-way-to-find-and-print-signal-strength-of-a-cell-phone-in-androi) – MohanKumar Nov 02 '19 at 17:05
  • I was hoping to find a way to get the value of signal strength to print on my emulator screen, but it either crashes or just prints the location. @MohanKumar – code2315 Nov 04 '19 at 20:40

0 Answers0