Introduction to Android wifimanager. wifilock

Source: Internet
Author: User

After checking the information on the Internet, the system will shut down the WiFi in about two minutes after the phone screen is closed and other applications are not using WiFi, make WiFi sleep.

This approach is conducive to saving power and extending the battery life.

Android provides a wifilock lock for WiFi, which can prevent WiFi from going to sleep and keep WiFi active. This lock is suitable for downloading a large file.

Wifilock allows an application to keep the Wi-Fi radio awake.

1. Create a wifilock

1.

/***** @ Param lockname * Lock name * @ return wifilock */Public wifilock createwifilock (string lockname) {wifilock = wifimanager. createwifilock (lockname); Return wifilock ;}


2.

/***** @ Param lockname * Lock name * @ Param locktype ** wifi_mode_full = 1 <br/> * scan, automatically try to connect to a previously configured point <br/> * wifi_mode_scan_only = 2 <br/> * only scans left <br/> * wifi_mode_full_high_perf = 3 <br/> * Based on the first mode, best Performance <br/> * @ return wifilock */Public wifilock createwifilock (string lockname, int locktype) {wifilock = wifimanager. createwifilock (locktype, lockname); Return wifilock ;}


2. Add locks to wifi

/*** Lock */Public void lockwifi () {wifilock. Acquire ();}


3. release locks for WiFi

/*** Release lock */Public void releaselock () {If (wifilock. isheld () {wifilock. Release ();}}


4. Determine whether WiFi is locked or not

/*** Determine whether the WiFi lock holds ** @ return */Public Boolean isheld () {return wifilock. isheld ();}



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.