I am writing a software connection to a wifi device. I do it via Broadcast Recessiver. I already killed a lot of time in the end I achieved stable work on all androids except 8. At 8, the standard code does not work! Here is the connection code itself:

public void setWifiConnection1(View view){ WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); WifiConfiguration conf = new WifiConfiguration(); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); conf.SSID = "\"NETWORK_NAME\""; conf.preSharedKey = "\"PASSWORD\""; int netId = wifi.addNetwork(conf); if (netId == -1) { netId = getExistingNetworkId(conf.SSID); } wifi.enableNetwork(netId, true); wifi.reconnect(); } private int getExistingNetworkId(String SSID) { WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> configuredNetworks = wifiManager.getConfiguredNetworks(); if (configuredNetworks != null) { for (WifiConfiguration existingConfig : configuredNetworks) { if (existingConfig.SSID.equals(SSID)) { return existingConfig.networkId; } } } return -1; } 

I add the line wifi.disconnect (); Connect only for 35 seconds.

  wifi.disconnect(); wifi.enableNetwork(netId, true); wifi.reconnect(); 

Here is the entire connection code with the form

I would be very grateful for any advice and tips on how to achieve stable operation on 8-ke!

    1 answer 1

    Eight simply saves the battery, if there is no traffic, then everything is logical. You can make an infinite stream, and in it already call what is needed, either through Runnable and write to run() what is needed for the application logic