well, the problem is solved by myself. what i do is just put the wifi.startScan()
on the onRecieve()
method and with the help from an integer named count
so my code is look like this now:
x = new BroadcastReceiver()
{
@Override
public void onReceive(Context c, Intent intent)
{
datavar.execSQL("delete from hasilscan");
results = wifi.getScanResults();
size = results.size();
if (size > 0) {
for (int i=0; i<size; i++){
ScanResult scanresult = wifi.getScanResults().get(i);
int rssi = scanresult.level;
String bssid = scanresult.BSSID;
datavar.execSQL("insert into hasilscan values('"+bssid+"',"+rssi+")");
}
count++;
if (count < 12) { //because i want the wifi scan to be repeated 12 times in a row
wifi.startScan();
} else {
unregisterReceiver(x); //stops the continuous scan
}
} else {
unregisterReceiver(x);
Toast.makeText(MainActivity.this, "FAIL", Toast.LENGTH_LONG).show();
}
}
};
with this code, the new scan is started after the previous scan is done so it wont interrupt the previous scan