NetworkInfo
open classNetworkInfo: Parcelable
kotlin.Any | |
↳ | android.net.NetworkInfo |
Describes the status of a network interface.
Use ConnectivityManager#getActiveNetworkInfo()
to get an instance that represents the current network connection.
Summary
Nested classes | |
---|---|
The fine-grained state of a network connection. |
|
Coarse-grained network state. |
Inherited constants | |
---|---|
Public constructors | |
---|---|
NetworkInfo(type: Int, subtype: Int, typeName: String?, subtypeName: String?) Create a new instance of NetworkInfo. |
Public methods | |
---|---|
open Int | |
open NetworkInfo.DetailedState |
Reports the current fine-grained state of the network. |
open String! |
Report the extra information about the network state, if any was provided by the lower networking layers. |
open String! |
Report the reason an attempt to establish connectivity failed, if one is available. |
open NetworkInfo.State! |
getState() Reports the current coarse-grained state of the network. |
open Int |
Return a network-type-specific integer describing the subtype of the network. |
open String! |
Return a human-readable name describing the subtype of the network. |
open Int |
getType() Reports the type of network to which the info in this |
open String! |
Return a human-readable name describe the type of the network, for example "WIFI" or "MOBILE". |
open Boolean |
Indicates whether network connectivity is possible. |
open Boolean |
Indicates whether network connectivity exists and it is possible to establish connections and pass data. |
open Boolean |
Indicates whether network connectivity exists or is in the process of being established. |
open Boolean |
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. |
open Boolean |
Indicates whether the device is currently roaming on this network. |
open Unit |
setDetailedState(detailedState: NetworkInfo.DetailedState, reason: String?, extraInfo: String?) Sets the fine-grained state of the network. |
open String |
toString() |
open Unit |
writeToParcel(dest: Parcel, flags: Int) |
Properties | |
---|---|
static Parcelable.Creator<NetworkInfo!> |
Public constructors
NetworkInfo
NetworkInfo(
type: Int,
subtype: Int,
typeName: String?,
subtypeName: String?)
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
open fundescribeContents(): Int
Deprecated: Deprecated in Java.
Return | |
---|---|
Int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR |
getDetailedState
open fungetDetailedState(): NetworkInfo.DetailedState
Deprecated: Apps should instead use the android.net.ConnectivityManager.NetworkCallback
API to learn about connectivity changes. See android.net.ConnectivityManager#registerDefaultNetworkCallback and android.net.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.
Return | |
---|---|
NetworkInfo.DetailedState |
the fine-grained state This value cannot be null . |
getExtraInfo
open fungetExtraInfo(): String!
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.
Return | |
---|---|
String! |
the extra information, or null if not available |
getReason
open fungetReason(): String!
Deprecated: 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.
Return | |
---|---|
String! |
the reason for failure, or null if not available |
getState
open fungetState(): NetworkInfo.State!
Deprecated: Apps should instead use the android.net.ConnectivityManager.NetworkCallback
API to learn about connectivity changes. android.net.ConnectivityManager#registerDefaultNetworkCallback and android.net.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.
Return | |
---|---|
NetworkInfo.State! |
the coarse-grained state |
getSubtype
open fungetSubtype(): Int
Deprecated: Use android.telephony.TelephonyManager#getDataNetworkType
instead.
Return a network-type-specific integer describing the subtype of the network.
Return | |
---|---|
Int |
the network subtype |
getSubtypeName
open fungetSubtypeName(): String!
Deprecated: Use android.telephony.TelephonyManager#getDataNetworkType
instead.
Return a human-readable name describing the subtype of the network.
Return | |
---|---|
String! |
the name of the network subtype |
getType
open fungetType(): Int
Deprecated: 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.
Return | |
---|---|
Int |
one of ConnectivityManager#TYPE_MOBILE , android.net.ConnectivityManager#TYPE_WIFI , ConnectivityManager#TYPE_WIMAX , android.net.ConnectivityManager#TYPE_ETHERNET , ConnectivityManager#TYPE_BLUETOOTH , or other types defined by ConnectivityManager . |
getTypeName
open fungetTypeName(): String!
Deprecated: 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".
Return | |
---|---|
String! |
the name of the network type |
isAvailable
open funisAvailable(): Boolean
Deprecated: Apps should instead use the android.net.ConnectivityManager.NetworkCallback
API to learn about connectivity changes. android.net.ConnectivityManager#registerDefaultNetworkCallback and android.net.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.
Return | |
---|---|
Boolean |
true if the network is available, false otherwise |
isConnected
open funisConnected(): Boolean
Deprecated: Apps should instead use the android.net.ConnectivityManager.NetworkCallback
API to learn about connectivity changes. See android.net.ConnectivityManager#registerDefaultNetworkCallback and android.net.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.
Return | |
---|---|
Boolean |
true if network connectivity exists, false otherwise. |
isConnectedOrConnecting
open funisConnectedOrConnecting(): Boolean
Deprecated: Apps should instead use the android.net.ConnectivityManager.NetworkCallback
API to learn about connectivity changes. android.net.ConnectivityManager#registerDefaultNetworkCallback and android.net.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.
Return | |
---|---|
Boolean |
true if network connectivity exists or is in the process of being established, false otherwise. |
isFailover
open funisFailover(): Boolean
Deprecated: 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.
Return | |
---|---|
Boolean |
true if this is a failover attempt, false otherwise. |
isRoaming
open funisRoaming(): Boolean
Deprecated: 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.
Return | |
---|---|
Boolean |
true if roaming is in effect, false otherwise. |
setDetailedState
open funsetDetailedState(
detailedState: NetworkInfo.DetailedState,
reason: String?,
extraInfo: String?
): Unit
Deprecated: Use NetworkCapabilities
instead.
Sets the fine-grained state of the network. This is only useful for testing.
Parameters | |
---|---|
detailedState |
NetworkInfo.DetailedState: the DetailedState . This value cannot be null . |
reason |
String?: a String indicating the reason for the state change, if one was supplied. May be null . |
extraInfo |
String?: an optional String providing additional network state information passed up from the lower networking layers. This value may be null . |
toString
open funtoString(): String
Deprecated: Deprecated in Java.
Return | |
---|---|
String |
a string representation of the object. |
writeToParcel
open funwriteToParcel(
dest: Parcel,
flags: Int
): Unit
Deprecated: Deprecated in Java.
Parameters | |
---|---|
dest |
Parcel: The Parcel in which the object should be written. This value cannot be null . |
flags |
Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE . Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE , and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |