2014-07-09 47 views
-1

在我的新項目中,我需要在烤麪包中顯示dbm。我從來沒有用過信號強度。我在互聯網上搜索了很多,但沒有找到任何好的信息。在我的想象中,它應該是非常容易的,但我無法建立一些有效的東西。 你能幫我嗎?獲取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;  
+0

那麼問題是什麼? – eleven

+0

嘗試在'this'處放置'getApplicationContext()'.. –

回答

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