android获取wifi信号强度

转载:http://www.cxybl.com/html/android/20120428/23302.html


android获取wifi信号强度

android 获取wifi 信号质量: int strength = WifiManager.calculateSignalLevel(info.getRssi(), 5);即信号强度。 获取方法: private String obtainWifiInfo() { // Wifi的连接速度及信号强度: WifiManager wifiManager = (WifiManager) getSystemService

android 获取wifi 信号质量:
int strength = WifiManager.calculateSignalLevel(info.getRssi(), 5);即信号强度。
获取方法:
private String obtainWifiInfo() {
// Wifi的连接速度及信号强度:
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
// WifiInfo wifiInfo = wifiManager.getConnectionInfo();
WifiInfo info = wifiManager.getConnectionInfo();
if (info.getBSSID() != null) {
// 链接信号强度
int strength = WifiManager.calculateSignalLevel(info.getRssi(), 5);
// 链接速度
int speed = info.getLinkSpeed();
// 链接速度单位
String units = WifiInfo.LINK_SPEED_UNITS;
// Wifi源名称
String ssid = info.getSSID();
}
return info.toString();
}
//////////////////////////// wifi 信号变化 :
注册 receiver,
public BroadcastReceiver rssiReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

        }
    };
    @Override
    public void onResume() {
        super.onResume();
        registerReceiver(rssiReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));
        
        Log.d("Rssi", "Registered");
    }
    @Override
    public void onPause() {
        super.onPause();
        
        unregisterReceiver(rssiReceiver);
        Log.d("Rssi", "Unregistered");
    }


你可能感兴趣的:(android,String,service,null,action)