3

I am developing an Android app that should connect to a network and monitor the signal strength. I have achieved to connect and see the strength, but I don´t know how to actively "hear" and display the strength. This is my method for monitoring:

public void search(View v) {

        // Turn on wifi
        if (!wifi.isWifiEnabled()) {
            if (wifi.getWifiState() != WifiManager.WIFI_STATE_ENABLING) {
                wifi.setWifiEnabled(true);
            }
        }

        // Register the desired network
        int nId = wifi.addNetwork(netConfig);

        // create the BroadcastReciever
        if (wifiReciever == null) {
            wifiReciever = new BroadcastReceiver() {

                @Override
                public void onReceive(Context context, Intent intent) {
                    final String action = intent.getAction();
                    if (action
                            .equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
                        if (intent.getBooleanExtra(
                                WifiManager.EXTRA_SUPPLICANT_CONNECTED, false)) {
                            message.setText("Connected: "
                                    + wifi.getConnectionInfo().getRssi());
                        } else {
                            message.setText("Disconnected...");
                        }
                    } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
                        message.setText("Connected: "
                                + wifi.getConnectionInfo().getRssi());
                    }
                }
            };
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
        intentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
        registerReceiver(wifiReciever, intentFilter);

        // intentamos conectarnos
        wifi.enableNetwork(nId, true);

    }

This code works sometimes, but it does not update the strength very often. Is there a API or any other methods/hidden apis for doing what I want to do?

Any help would be great!

Sebastian Breit
  • 6,137
  • 1
  • 35
  • 53
  • possible duplicate of [Android: How to monitor WiFi signal strength](http://stackoverflow.com/questions/1206891/android-how-to-monitor-wifi-signal-strength) – mike47 Dec 18 '14 at 21:02

1 Answers1

1

Wifi signal strength (like current network activity, or CPU usage) is not a quantity that can be listened for without polling the sensor. Other wifi monitor apps simply poll at a user-defined interval. There is a substantial amount of noise and volatility in the wifi signal measurement, so you can't just wait for it to change. As far as I can tell, that intent is only broadcast when there is a substantial change in signal strength, and thus is not suitable for a live monitor.

Charles Munger
  • 1,417
  • 12
  • 11
  • Just like you said, I am polling the sensor every second and it seems to work. But it works much better when I am connected to the AP. You know why this happens? – Sebastian Breit Oct 02 '12 at 09:10
  • well ilñl accept this answer because the bounty is going to finish... but I'm pretty sure there must be a way to do what I want :S – Sebastian Breit Oct 07 '12 at 12:48
  • This is not correct. You can use a listener to do so, and do not need to poll the sensor. Some examples can be seen [here](http://stackoverflow.com/q/1206891/1992342) and [here](http://stackoverflow.com/q/18831442/1992342). – mike47 Dec 18 '14 at 20:58