NetworkInfo
  public
  
  
  
  class
  NetworkInfo
  
    extends Object
  
  
  
  
  
      implements
      
        Parcelable
      
  
  
| java.lang.Object | |
| ↳ | android.net.NetworkInfo | 
      This class was deprecated
      in API level 29.
    Callers should instead use the ConnectivityManager.NetworkCallback API to
             learn about connectivity changes, or switch to use
             ConnectivityManager.getNetworkCapabilities or
             ConnectivityManager.getLinkProperties to get information synchronously. Keep
             in mind that while callbacks are guaranteed to be called for every event in order,
             synchronous calls have no such constraints, and as such it is unadvisable to use the
             synchronous methods inside the callbacks as they will often not offer a view of
             networking that is consistent (that is: they may return a past or a future state with
             respect to the event being processed by the callback). Instead, callers are advised
             to only use the arguments of the callbacks, possibly memorizing the specific bits of
             information they need to keep from one callback to another.
  
Describes the status of a network interface.
Use ConnectivityManager.getActiveNetworkInfo() to get an instance that represents
 the current network connection.
Summary
| Inherited constants | 
|---|
| Fields | |
|---|---|
| 
    public
    static
    final
    Creator<NetworkInfo> | CREATOR
 | 
| Public constructors | |
|---|---|
| 
      NetworkInfo(int type, int subtype, String typeName, String subtypeName)
      Create a new instance of NetworkInfo. | |
| Public methods | |
|---|---|
| 
        
        
        
        
        
        int | 
      describeContents()
      Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. | 
| 
        
        
        
        
        
        NetworkInfo.DetailedState | 
      getDetailedState()
      
      This method is deprecated.
    Apps should instead use the
              | 
| 
        
        
        
        
        
        String | 
      getExtraInfo()
      This method is deprecated. Use other services e.g. WifiManager to get additional information passed up from the lower networking layers. | 
| 
        
        
        
        
        
        String | 
      getReason()
      This method was deprecated in API level 28. This method does not have a consistent contract that could make it useful to callers. | 
| 
        
        
        
        
        
        NetworkInfo.State | 
      getState()
      
      This method was deprecated
      in API level 28.
    Apps should instead use the
              | 
| 
        
        
        
        
        
        int | 
      getSubtype()
      
      This method was deprecated
      in API level 29.
    Use  | 
| 
        
        
        
        
        
        String | 
      getSubtypeName()
      
      This method was deprecated
      in API level 29.
    Use  | 
| 
        
        
        
        
        
        int | 
      getType()
      
      This method was deprecated
      in API level 28.
    Callers should switch to checking  | 
| 
        
        
        
        
        
        String | 
      getTypeName()
      
      This method was deprecated
      in API level 28.
    Callers should switch to checking  | 
| 
        
        
        
        
        
        boolean | 
      isAvailable()
      
      This method was deprecated
      in API level 28.
    Apps should instead use the
              | 
| 
        
        
        
        
        
        boolean | 
      isConnected()
      
      This method is deprecated.
    Apps should instead use the
              | 
| 
        
        
        
        
        
        boolean | 
      isConnectedOrConnecting()
      
      This method was deprecated
      in API level 28.
    Apps should instead use the
              | 
| 
        
        
        
        
        
        boolean | 
      isFailover()
      This method was deprecated in API level 28. This field is not populated in recent Android releases, and does not make a lot of sense in a multi-network world. | 
| 
        
        
        
        
        
        boolean | 
      isRoaming()
      
      This method was deprecated
      in API level 28.
    Callers should switch to checking
              | 
| 
        
        
        
        
        
        void | 
      setDetailedState(NetworkInfo.DetailedState detailedState, String reason, String extraInfo)
      
      This method was deprecated
      in API level 29.
    Use  | 
| 
        
        
        
        
        
        String | 
      toString()
      Returns a string representation of the object. | 
| 
        
        
        
        
        
        void | 
      writeToParcel(Parcel dest, int flags)
      Flatten this object in to a Parcel. | 
| Inherited methods | |
|---|---|
Fields
CREATOR
public static final Creator<NetworkInfo> CREATOR
Public constructors
NetworkInfo
public NetworkInfo (int type, 
                int subtype, 
                String typeName, 
                String subtypeName)Create a new instance of NetworkInfo. This may be useful for apps to write unit tests.
| Parameters | |
|---|---|
| type | int: the legacy type of the network, as one of the ConnectivityManager.TYPE_*
             constants. | 
| subtype | int: the subtype if applicable, as one of the TelephonyManager.NETWORK_TYPE_*
                constants. | 
| typeName | String: a human-readable string for the network type, or an empty string or null. | 
| subtypeName | String: a human-readable string for the subtype, or an empty string or null. | 
Public methods
describeContents
public int describeContents ()
Describe the kinds of special objects contained in this Parcelable
 instance's marshaled representation. For example, if the object will
 include a file descriptor in the output of writeToParcel(android.os.Parcel, int),
 the return value of this method must include the
 CONTENTS_FILE_DESCRIPTOR bit.
| Returns | |
|---|---|
| int | a bitmask indicating the set of special object types marshaled
 by this Parcelable object instance.
 Value is either 0orCONTENTS_FILE_DESCRIPTOR | 
getDetailedState
public NetworkInfo.DetailedState getDetailedState ()
      This method is deprecated.
    Apps should instead use the
             ConnectivityManager.NetworkCallback API to
             learn about connectivity changes. See
             ConnectivityManager.registerDefaultNetworkCallback and
             ConnectivityManager.registerNetworkCallback. These will
             give a more accurate picture of the connectivity state of
             the device and let apps react more easily and quickly to changes.
  
Reports the current fine-grained state of the network.
| Returns | |
|---|---|
| NetworkInfo.DetailedState | the fine-grained state
 This value cannot be null. | 
getExtraInfo
public String getExtraInfo ()
      This method is deprecated.
    Use other services e.g. WifiManager to get additional information passed up from
             the lower networking layers.
  
Report the extra information about the network state, if any was provided by the lower networking layers.
| Returns | |
|---|---|
| String | the extra information, or null if not available | 
getReason
public String getReason ()
      This method was deprecated
      in API level 28.
    This method does not have a consistent contract that could make it useful
             to callers.
  
Report the reason an attempt to establish connectivity failed, if one is available.
| Returns | |
|---|---|
| String | the reason for failure, or null if not available | 
getState
public NetworkInfo.State getState ()
      This method was deprecated
      in API level 28.
    Apps should instead use the
             ConnectivityManager.NetworkCallback API to
             learn about connectivity changes.
             ConnectivityManager.registerDefaultNetworkCallback and
             ConnectivityManager.registerNetworkCallback. These will
             give a more accurate picture of the connectivity state of
             the device and let apps react more easily and quickly to changes.
  
Reports the current coarse-grained state of the network.
| Returns | |
|---|---|
| NetworkInfo.State | the coarse-grained state | 
getSubtype
public int getSubtype ()
      This method was deprecated
      in API level 29.
    Use TelephonyManager.getDataNetworkType() instead.
  
Return a network-type-specific integer describing the subtype of the network.
| Returns | |
|---|---|
| int | the network subtype | 
getSubtypeName
public String getSubtypeName ()
      This method was deprecated
      in API level 29.
    Use TelephonyManager.getDataNetworkType() instead.
  
Return a human-readable name describing the subtype of the network.
| Returns | |
|---|---|
| String | the name of the network subtype | 
getType
public int getType ()
      This method was deprecated
      in API level 28.
    Callers should switch to checking NetworkCapabilities.hasTransport
             instead with one of the NetworkCapabilities#TRANSPORT_* constants :
             getType() and getTypeName() cannot account for networks using
             multiple transports. Note that generally apps should not care about transport;
             NetworkCapabilities.NET_CAPABILITY_NOT_METERED and
             NetworkCapabilities.getLinkDownstreamBandwidthKbps are calls that
             apps concerned with meteredness or bandwidth should be looking at, as they
             offer this information with much better accuracy.
  
Reports the type of network to which the
 info in this NetworkInfo pertains.
| Returns | |
|---|---|
| int | one of ConnectivityManager.TYPE_MOBILE,ConnectivityManager.TYPE_WIFI,ConnectivityManager.TYPE_WIMAX,ConnectivityManager.TYPE_ETHERNET,ConnectivityManager.TYPE_BLUETOOTH, or other
 types defined byConnectivityManager. | 
getTypeName
public String getTypeName ()
      This method was deprecated
      in API level 28.
    Callers should switch to checking NetworkCapabilities.hasTransport
             instead with one of the NetworkCapabilities#TRANSPORT_* constants :
             getType() and getTypeName() cannot account for networks using
             multiple transports. Note that generally apps should not care about transport;
             NetworkCapabilities.NET_CAPABILITY_NOT_METERED and
             NetworkCapabilities.getLinkDownstreamBandwidthKbps are calls that
             apps concerned with meteredness or bandwidth should be looking at, as they
             offer this information with much better accuracy.
  
Return a human-readable name describe the type of the network, for example "WIFI" or "MOBILE".
| Returns | |
|---|---|
| String | the name of the network type | 
isAvailable
public boolean isAvailable ()
      This method was deprecated
      in API level 28.
    Apps should instead use the
             ConnectivityManager.NetworkCallback API to
             learn about connectivity changes.
             ConnectivityManager.registerDefaultNetworkCallback and
             ConnectivityManager.registerNetworkCallback. These will
             give a more accurate picture of the connectivity state of
             the device and let apps react more easily and quickly to changes.
  
Indicates whether network connectivity is possible. A network is unavailable when a persistent or semi-persistent condition prevents the possibility of connecting to that network. Examples include
- The device is out of the coverage area for any network of this type.
- The device is on a network other than the home network (i.e., roaming), and data roaming has been disabled.
- The device's radio is turned off, e.g., because airplane mode is enabled.
true, because the system only
 returns info for available networks.
    | Returns | |
|---|---|
| boolean | trueif the network is available,falseotherwise | 
isConnected
public boolean isConnected ()
      This method is deprecated.
    Apps should instead use the
             ConnectivityManager.NetworkCallback API to
             learn about connectivity changes. See
             ConnectivityManager.registerDefaultNetworkCallback and
             ConnectivityManager.registerNetworkCallback. These will
             give a more accurate picture of the connectivity state of
             the device and let apps react more easily and quickly to changes.
  
Indicates whether network connectivity exists and it is possible to establish connections and pass data.
Always call this before attempting to perform data transactions.
| Returns | |
|---|---|
| boolean | trueif network connectivity exists,falseotherwise. | 
isConnectedOrConnecting
public boolean isConnectedOrConnecting ()
      This method was deprecated
      in API level 28.
    Apps should instead use the
             ConnectivityManager.NetworkCallback API to
             learn about connectivity changes.
             ConnectivityManager.registerDefaultNetworkCallback and
             ConnectivityManager.registerNetworkCallback. These will
             give a more accurate picture of the connectivity state of
             the device and let apps react more easily and quickly to changes.
  
Indicates whether network connectivity exists or is in the process
 of being established. This is good for applications that need to
 do anything related to the network other than read or write data.
 For the latter, call isConnected() instead, which guarantees
 that the network is fully usable.
| Returns | |
|---|---|
| boolean | trueif network connectivity exists or is in the process
 of being established,falseotherwise. | 
isFailover
public boolean isFailover ()
      This method was deprecated
      in API level 28.
    This field is not populated in recent Android releases,
             and does not make a lot of sense in a multi-network world.
  
Indicates whether the current attempt to connect to the network resulted from the ConnectivityManager trying to fail over to this network following a disconnect from another network.
| Returns | |
|---|---|
| boolean | trueif this is a failover attempt,falseotherwise. | 
isRoaming
public boolean isRoaming ()
      This method was deprecated
      in API level 28.
    Callers should switch to checking
             NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING
             instead, since that handles more complex situations, such as
             VPNs.
  
Indicates whether the device is currently roaming on this network. When
 true, it suggests that use of data on this network may incur
 extra costs.
| Returns | |
|---|---|
| boolean | trueif roaming is in effect,falseotherwise. | 
setDetailedState
public void setDetailedState (NetworkInfo.DetailedState detailedState, String reason, String extraInfo)
      This method was deprecated
      in API level 29.
    Use NetworkCapabilities instead.
  
Sets the fine-grained state of the network. This is only useful for testing.
| Parameters | |
|---|---|
| detailedState | NetworkInfo.DetailedState: theDetailedState.
 This value cannot benull. | 
| reason | String: aStringindicating the reason for the state change,
 if one was supplied. May benull. | 
| extraInfo | String: an optionalStringproviding additional network state
 information passed up from the lower networking layers.
 This value may benull. | 
toString
public String toString ()
Returns a string representation of the object.
| Returns | |
|---|---|
| String | a string representation of the object. | 
writeToParcel
public void writeToParcel (Parcel dest, int flags)
Flatten this object in to a Parcel.
| Parameters | |
|---|---|
| dest | Parcel: The Parcel in which the object should be written.
 This value cannot benull. | 
| flags | int: Additional flags about how the object should be written.
 May be 0 orParcelable.PARCELABLE_WRITE_RETURN_VALUE.
 Value is either0or a combination ofParcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES | 
