Android-wifi Network Operation < 10 >

Source: Internet
Author: User

Status of 1.wifi

Constant name constant value NIC status

Wifi_state_disabled:1: WiFi nic is not available

wifi_state_disabling:0: WiFi is shutting down

Wifi_state_enabled:3: WiFi card available

Wifi_state_enabling:2: WiFi card is open

WIFI Wifi_state_unknown:4: Unknown NIC status

2.wifi usage rights

There are four main operating privileges for WIFI:

Change_network_state: Permission to modify network status is allowed.      

Change_wifi_state: Permission to modify the WIFI status is allowed.          

Access_network_state: Permission to allow access to network status.              

access_wifi_state: Permission to allow access to the WIFI status.  

Add permissions in the Androidmanifest.xml file.

1     <uses-permissionAndroid:name= "Android.permission.CHANGE_NETWORK_STATE"></uses-permission>       2 3     <uses-permissionAndroid:name= "Android.permission.CHANGE_WIFI_STATE"></uses-permission>    4 5     <uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE"></uses-permission>     6 7     <uses-permissionAndroid:name= "Android.permission.ACCESS_WIFI_STATE"></uses-permission> 

Operation of 3.wifi network card

   operation of the WiFi network card requires a Wifimanager (Class) object, the method to get the object is as follows: &NBSP;
      wifimanager wifimanger= (Wifimanger) Context.getsystemservice (Service.wifi-service); &NBSP;
      turn on wifi card &NBSP;
      wifimanager.setwifienabled (true); Span class= "Apple-converted-space" >&NBSP;
      turn off WiFi NIC &NBSP;
      wifimanager.setwifienabled (false);  
       gets the current status of the NIC &NBSP;
       wifimanager.getwifistate ();

Note: WiFi, Bluetooth function can only be debugged on the phone.

Android-wifi Network Operation < 10 >

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.