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!