Android Development WiFi Basics Tutorial _android

Source: Internet
Author: User

This example describes the basics of Android's WiFi development. Share to everyone for your reference. Specifically as follows:

Android provides the Wifimanager class, which enables WiFi-related operations.

Pass

 
 

You can get an instance of the class.

1. Get WiFi on (as long as WiFi on the phone is turned on and is not connected to a WiFi connection):

Boolean isOpen = wifimanager.iswifienabled (); 

2. Modify WiFi status, through the parameters to open WiFi or turn off WiFi

Wifimanager.setwifienabled (TRUE); 

3. Access to nearby WiFi (must be in the case of WiFi already open)

list<scanresult> list = Wifimanager.getscanresults (); 

4. Get the WiFi on the current connection

Wifiinfo wifiinfo = Wifimanager.getconnectioninfo (); 

5. Get the current list of WiFi configurations (that is, the WiFi list displayed on the page when the phone is connected to WiFi)

list<wificonfiguration> configlist = Wifimanager.getconfigurednetworks (); 

6. Connect/Disconnect Some WiFi (note: WiFi will not change the open state)

Connection, the first parameter is the net ID of a WiFi that is returned in Wifimanager.getconfigurednetworks () or Wifimanager.getconnectioninfo (). The second parameter is whether to turn off other WiFi while connecting to the WiFi

Wifimanager.enablenetwork (NetID, true); 

Disconnect, parameter meaning ditto

Wifimanager.disablenetwork (NetID); 
Wifimanager.disconnect ();

Full instance code click here to download the site.

I hope this article will help you with your Android program.

Related Article

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.