WiFi network operation

Source: Internet
Author: User

WiFi NIC status (unavailable status value is 1, closing value is 0, available status value is 3, opening value is 2)

The WiFi NIC status is represented by a series of integer constants that are stored in the Wifimanager class

1, wifi_state_disabled WIFI network card is not available

2. Wifi_state_disabling WIFI is shutting down

3, wifi_state_enabled WIFI network card available

4, wifi_state_enabling WIFI network card is open

5. Wifi_state_unknown Unknown NIC Status

Permission to operate the WiFi network card, declared in Androidmanifest.xml:

<uses-permission android:name= "Android.permission.RECEIVE_SMS"/>
<uses-permission android:name= "Android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name= "Android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/>

Open the WiFi card code:

Wifimanager Wifimanager = (wifimanager) OtherActivity.this.getSystemService (Context.wifi_service);
Wifimanager.setwifienabled (TRUE); Turn on the WiFi card
Toast.maketext (otheractivity.this, "Current WiFi card status" + Wifimanager.getwifistate (), Toast.length_long). Show (); Output current WiFi status

Turn off the WiFi card code:

Wifimanager.setwifienabled (FALSE); Turn on the WiFi card

Get WiFi Card status:

Wifimanager.getwifistate ();

WiFi network operation

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.