Android set WiFi non-sleep and ensure network communication is normal after black screen

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.