Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to prevent automatic connection to WiFi
    primarykey
    data
    text
    <p>I try to prevent automatic connection to WiFi and displaying dialog box after turning on WiFi adapter from notification bar. </p> <p>I register programmatically BroadcastReceiver that receives WIFI_STATE_CHANGED_ACTION. In WIFI_STATE_ENABLED I remove network from the configured network list. But it does not work. </p> <p>I register BroadcastReceiver in: </p> <pre><code>@Override protected void onStart() { super.onStart(); registerReceiver(wifiStatusReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION)); } </code></pre> <p>And unregister in onStop method. </p> <p>BroadcastReceiver code: </p> <pre><code>public class WiFiStatusReceiver extends BroadcastReceiver { private WifiManager wifiManager; @Override public void onReceive(Context context, Intent intent) { wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); if(!isInitialStickyBroadcast()) { //it is not a sticky intent switch(wifiManager.getWifiState()) { case WifiManager.WIFI_STATE_ENABLING: Toast.makeText(context, R.string.enabling_wifi, Toast.LENGTH_SHORT).show(); break; case WifiManager.WIFI_STATE_ENABLED: Toast.makeText(context, R.string.enabled_wifi, Toast.LENGTH_SHORT).show(); wifiManager.disconnect(); if(!wifiManager.getConfiguredNetworks().isEmpty()) { //there are some networks for(WifiConfiguration wifiConfig :wifiManager.getConfiguredNetworks()) { wifiManager.removeNetwork(wifiConfig.networkId); } } break; case WifiManager.WIFI_STATE_DISABLING: Toast.makeText(context, R.string.disabling_wifi, Toast.LENGTH_SHORT).show(); break; case WifiManager.WIFI_STATE_DISABLED: Toast.makeText(context, R.string.disabled_wifi, Toast.LENGTH_SHORT).show(); break; } } else { //is a sticky intent wifiManager.disconnect(); if(!wifiManager.getConfiguredNetworks().isEmpty()) { //there are some networks for(WifiConfiguration wifiConfig :wifiManager.getConfiguredNetworks()) { wifiManager.removeNetwork(wifiConfig.networkId); } } } } </code></pre> <p>}</p> <p>Any suggestions ? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload