One, about WiFi does not sleep, two kinds of settings
1. Through the mobile settings interface to enter, settings-Wireless and network--wlan--advanced settings-sleep during the WLAN to keep open-always.
2. Set by code
Get Set Value
int Wifisleepvalue=settings.system.getint (Getcontentresolver (), Settings.System.WIFI_SLEEP_POLICY,
Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
Set to "Always"
Settings.System.putInt (Getcontentresolver (), Settings.System.WIFI_SLEEP_POLICY,
Settings.System.WIFI_SLEEP_POLICY_NEVER);
It is recommended that when the program starts, record the original value, set the "Always", and restore the original settings of the phone when exiting the program.
Note Add permissions: <uses-permission android:name= "Android.permission.WRITE_SETTINGS"/>
Second, how to ensure the black screen after the normal network communication
Individuals in the above settings, the mobile phone test, found that the program in the black screen, the network is still dormant, but on average every 30 seconds or so will reconnect once.
Later debugging found that when the service was adopted, the network connection continued to keep smooth. And regardless of WiFi hibernation policy settings, the black screen will be able to stay connected later.
The above situation may relate to each handset terminal, only for reference.