【问题标题】:Get the dbm in a toast让 dbm 干杯
【发布时间】:2014-08-30 13:03:52
【问题描述】:

在我的新项目中,我需要在 Toast 中显示 dbm。我以前从未使用过信号强度。我在互联网上搜索了很多,但我没有找到任何好的信息。在我的想象中,这应该很容易,但我无法构建可行的东西。 你能帮帮我吗?

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;     

【问题讨论】:

  • 那有什么问题?
  • 尝试将getApplicationContext() 放在this 的位置..

标签: android signal-strength dbm


【解决方案1】:

无线网络:

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

蜂窝网络:

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

在你的Toast

Toast.makeText(this, "signal strength is " + linkSpeed + " dBm",
Toast.LENGTH_SHORT).show();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多