Android 为dbm干杯

Android 为dbm干杯,android,signal-strength,dbm,Android,Signal Strength,Dbm,在我的新项目中,我需要向dbm敬酒。我以前从未使用过信号强度。我在网上搜索了很多,但没有找到任何好的信息。在我的想象中,这应该很容易,但我无法构建出有效的东西。 你能帮我吗 Button btn=(Button)findViewById(R.id.start); btn.setOnClickListener(this); } public void onClick(View v) { switch (v.getId()) { ca

在我的新项目中,我需要向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;     
Wifi:

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();
移动电话:

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.makeText(this, "signal strength is " + linkSpeed + " dBm",
Toast.LENGTH_SHORT).show();

那么问题出在哪里呢?试着把
getApplicationContext()
放在
this
的位置。。