WiFi Internet access (i)

Source: Internet
Author: User

One,what are the status of the WIFI card?

WIFI Total has the following five states, which is actually some of the shaping constants:

1. wifi_state_disabled: WIFI is not available, the value is: 1 .

2. wifi_state_disabling: WiFi is shutting down, due to WiFi off is required this process, this state means that WiFi is shutting down the process, the value is: 0 c8>.

3. wifi_state_enabled: WIFI can be used, the value is: 3 .

4. wifi_state_enabling: WIFI is on, the reason is the same as wifi_state_disabling, The value is: 2 .

5. Wifi_state_unknown: Unknown network card status, when the phone or program has some errors caused by WIFI is not available will be this state, the value is: 4 .

Second, the operation of WIFI need to get permission

To get access to the operation of WiFi, you must know what the WiFi has, the main operating rights of WiFi has four:

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.

Claim action WIFI permissions are declared in the androidmanifest.xml file! Join:

    • <!--the permissions needed to get WiFi access to the network--
    • <uses-permission android:name= "Android.permission.CHANGE_NETWORK_STATE" ></uses-permission>
    • <uses-permission android:name= "Android.permission.CHANGE_WIFI_STATE" ></uses-permission>
    • <uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE" ></uses-permission>
    • <uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE" ></uses-permission>

Third, change the status of WIFI

There are three main aspects involved in operating the WIFI status:

1. Through m_wifimanager=(Wifimanager) This.getsystemservice (context.wifi_service); get Wifimanager Object, this object is the root of our operating WiFi network card, whether it is to change the status of WiFi, or access to the status of WiFi, all through this object.

2.   Change   wifi  NIC status, involving a     method s etwifienabled   The parameter setting of this method can be implemented to open or close  wifi : true   means open,  , false   The indicates shutdown.

3. Get the status of the WiFi card, involving a Wifimanager method getwifistate, through this method, you can get the current status of WiFi, that is, the 1th said WIFI is one of five states.

Note:

1, some places useM_wifimanager= (Wifimanager) This.getsystemservice (Service. wifi_service   wifi_ SERVICE   wifimanager   Object, because  service  and activity are all   context ,   SERVICE and activity   wifi_service  is actually from  context  there inherited, so written  context.wifi_service  There is no problem.

Attached: You can also use the following method to get WiFi status

Get WiFi Open
public boolean iswifiactive ()
{
Get Connection Manager
Connectivitymanager connmng = (Connectivitymanager) This
. Getsystemservice (Context.connectivity_service);
if (connmng! = null)
{
networkinfo[] netinfor = Connmng.getallnetworkinfo ();
for (Networkinfo i:netinfor)
{
if (Connectivitymanager.type_wifi = = I.gettype ()
&& i.isconnected ())
{
Return true;//WiFi is already open
}
}
}
return false;
}

WiFi Internet access (i)

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.