如何获得wifi信号信息:力量,Android工作室链接速度?

时间:2015-09-13 12:52:24

标签: android android-activity wifi signal-strength ssid

我使用了以下代码,但我仍然遇到问题,它不会返回任何信息:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //initializeWiFiListener();

    }

    public void initializeWiFiListener() {

        String connectivity_context = Context.WIFI_SERVICE;

        final WifiManager wifi = (WifiManager) getSystemService(connectivity_context);

        if (!wifi.isWifiEnabled()) {

            if (wifi.getWifiState() != WifiManager.WIFI_STATE_ENABLING) {

                wifi.setWifiEnabled(true);
            }
        }

      registerReceiver(new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {

                WifiInfo info = wifi.getConnectionInfo();
                String ssid = info.getSSID();
                int rssi = info.getRssi();
                int speed = info.getLinkSpeed();
                TextView t1 = (TextView) findViewById(R.id.textView);
                t1.setText(ssid + " " + Integer.toString(rssi) + " " + Integer.toString(speed));
            }

        }, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));
    }

}

我的连接wifi没有任何信息。

如何获取wifi信号信息:强度,链接速度?

0 个答案:

没有答案