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()){}