-1

In my new project I need to show the dbm in a Toast. I have never before worked with the signal strength. I searched a lot on the internet but I did't find any good information. In my imagination it should be very easy, But I can't build something that works. Could you help me please?

Button btn=(Button)findViewById(R.id.start);
    btn.setOnClickListener(this);             
}

public void onClick(View v) {
    switch (v.getId()) {
           case R.id.start:
                Toast.makeText(this, "signal strength is " + this.signalDBM + "dBm", Toast.LENGTH_SHORT).show();
                break;     
anthonycr
  • 4,146
  • 1
  • 28
  • 35
user3379235
  • 29
  • 1
  • 6

1 Answers1

1

Wifi:

WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();

Cellular:

TelephonyManager telephonyManager = TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
int linkSpeed = cellSignalStrengthGsm.getDbm();

In your Toast:

Toast.makeText(this, "signal strength is " + linkSpeed + " dBm",
Toast.LENGTH_SHORT).show();
CodeWarrior
  • 5,026
  • 6
  • 30
  • 46