Android WifiLock WIFI_MODE_SCAN_ONLY not working

I am trying to block wifi connections. I want my application to turn on Wi-Fi, but not connect to any network that is already stored on the smartphone. But even after I use SCAN_ONLY mode, it continues to connect to networks that already “know”.

..... wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); ..... wifiManager.setWifiEnabled(true); WifiLock scanOnly = wifiManager.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, "scanOnly"); scanOnly.acquire(); 

Already in desperation, I tried to disconnect after making sure that the status is WIFI_STATE_ENABLED wifi. That the application cannot connect for a few seconds, but after a while it connects to the network in the same ...

  wifiManager.setWifiEnabled(true); .... WHEN (WIFI STATE == WIFI_STATE_ENABLED) {wifiManager.disconnect(); scanOnly.acquire();} 

Can someone help me? Tks

+8
android wifi wifimanager
source share
2 answers

WifiLock is not for this. Only for "Allows application to support Wi-Fi radio." This does not prevent anyone from connecting to Wi-Fi. He only says: "I want to be able to do at least this in sleep mode." You should do what you said above: get a list of all saved networks, and then turn off Wi-Fi in BroadcastReceiver.

 @Override public void onReceive(Context c, Intent intent) { saveWifiList(mainWifi.getScanResults()); unregisterReceiver(this); mainWifi.setWifiEnabled(false); showWifiList(); } 
+1
source share

One way is to get a list of all saved networks, and then turn them off. You may want to keep your state in order to restore the initial state after completion.

0
source share

All Articles