I have a broadcast receiver to scan the available networks, with the normal code that you can easily find here on StackOverflow.
I am putting on my layout an icon for each available network, the problem is that when a network is removed, it still shows it.
The problem is that for this broadcast receiver, the action/intent that it is listening is the SCAN_RESULTS_AVAILABLE_ACTION . In the beginning i can call the startScan(), but after that there will be no more scans. It only scans if i manually go to the wifi settings on my phone.
What would be a possible solution for this ? It should automatically remove the networks that are not available anymore, but in order to do that, it has to scan again, but i don't how i should "trigger" that scan again.
my code is :
public class WifiReceiver extends BroadcastReceiver {
private Vector<String> keywords;
public void onReceive(Context c, Intent intent) {
System.out.println("TOU AQUI NO WIFI RECEIVER !! ");
List<ScanResult> connResults=wifimanager.getScanResults();
List<String> scanResultsSSID = new ArrayList<>() ;
for(int i=0;i<connResults.size();i++){
String ssid=connResults.get(i).SSID;
scanResultsSSID.add(ssid);
if(ssid.contains("teste")){
System.out.println("Estou no : " + connResults.get(i).toString());
radarTextView.addKeyWord(ssid);
}
}
keywords=radarTextView.getKeyWords();
for(int j=0;j<keywords.size();j++){
String tmp=keywords.get(j);
System.out.println("this is one of the keyword : "+ tmp);
if(!scanResultsSSID.contains(tmp)){
radarTextView.removeKeyWord(tmp);
System.out.println("removed this : "+tmp);
}
}
radarTextView.show();
}
}
I know that i am only adding a network with the name "teste" but that is the name of the wifi on one of my phones that i am testing this. If i turn it off, it doesn't get removed from the other phone.