Android.net. connectivitymanager

Source: Internet
Author: User

This class is mainly used to query and determine network connection information.

ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);

Networkinfo getactivenetworkinfo () obtains the network information currently being connected. If no network connection is established, null is returned.

Networkinfo [] getallnetworkinfo () obtains all network information supported by the machine.

Networkinfo getnetworkinfo (INT networktype) obtains network information of a certain type.

Android.net. networkinfo class,

Boolean isavailable () indicates whether the Network is available (for example, WiFi info, false when WiFi is disabled)

Int GetType () obtains the network type corresponding to this information class. The Int value corresponds to the field in connectivitymanager.

String gettypename () to get the network type name, such as "WiFi ".

Boolean isconnected () determines whether the network is connected

Boolean isconnectedorconnecting () is connected or is being connected

Networkinfo. State getstate () to get the network status

The difference between networkinfo. detailedstate getdetailedstate () and the above method is that this method gets more detailed information.


Android.net. networkinfo. State is an enumeration class, which contains connected, connected, unconnected, and closed connections.


Determine whether the network is connected:

            ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);            NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();            if(networkInfo == null || !networkInfo.isConnected()){}


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.