NetworkInfo
public
class
NetworkInfo
extends Object
implements
Parcelable
| java.lang.Object | |
| ↳ | android.net.NetworkInfo |
Describes the status of a network interface.
Use getActiveNetworkInfo() to get an instance that represents
the current network connection.
Summary
Nested classes | |
|---|---|
enum |
NetworkInfo.DetailedState
The fine-grained state of a network connection. |
enum |
NetworkInfo.State
Coarse-grained network state. |
Inherited constants |
|---|
android.os.Parcelable
|
Fields | |
|---|---|
public
static
final
Creator<NetworkInfo> |
CREATOR
|
Public methods | |
|---|---|
int
|
describeContents()
Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
NetworkInfo.DetailedState
|
getDetailedState()
Reports the current fine-grained state of the network. |
String
|
getExtraInfo()
Report the extra information about the network state, if any was provided by the lower networking layers. |
String
|
getReason()
Report the reason an attempt to establish connectivity failed, if one is available. |
NetworkInfo.State
|
getState()
Reports the current coarse-grained state of the network. |
int
|
getSubtype()
Return a network-type-specific integer describing the subtype of the network. |
String
|
getSubtypeName()
Return a human-readable name describing the subtype of the network. |
int
|
getType()
Reports the type of network to which the
info in this |
String
|
getTypeName()
Return a human-readable name describe the type of the network, for example "WIFI" or "MOBILE". |
boolean
|
isAvailable()
Indicates whether network connectivity is possible. |
boolean
|
isConnected()
Indicates whether network connectivity exists and it is possible to establish connections and pass data. |
boolean
|
isConnectedOrConnecting()
Indicates whether network connectivity exists or is in the process of being established. |
boolean
|
isFailover()
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. |
boolean
|
isRoaming()
Indicates whether the device is currently roaming on this network. |
String
|
toString()
Returns a string representation of the object. |
void
|
writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel. |
Inherited methods | |
|---|---|
java.lang.Object
| |
android.os.Parcelable
| |
Fields
Public methods
describeContents
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(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. |
getDetailedState
NetworkInfo.DetailedState getDetailedState ()
Reports the current fine-grained state of the network.
| Returns | |
|---|---|
NetworkInfo.DetailedState |
the fine-grained state |
getExtraInfo
String getExtraInfo ()
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
String getReason ()
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
NetworkInfo.State getState ()
Reports the current coarse-grained state of the network.
| Returns | |
|---|---|
NetworkInfo.State |
the coarse-grained state |
getSubtype
int getSubtype ()
Return a network-type-specific integer describing the subtype of the network.
| Returns | |
|---|---|
int |
the network subtype |
getSubtypeName
String getSubtypeName ()
Return a human-readable name describing the subtype of the network.
| Returns | |
|---|---|
String |
the name of the network subtype |
getType
int getType ()
Reports the type of network to which the
info in this NetworkInfo pertains.
| Returns | |
|---|---|
int |
one of TYPE_MOBILE, TYPE_WIFI, TYPE_WIMAX, TYPE_ETHERNET, TYPE_BLUETOOTH, or other
types defined by ConnectivityManager
|
getTypeName
String getTypeName ()
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
boolean isAvailable ()
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.
| Returns | |
|---|---|
boolean |
true if the network is available, false otherwise
|
isConnected
boolean isConnected ()
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 |
true if network connectivity exists, false otherwise.
|
isConnectedOrConnecting
boolean isConnectedOrConnecting ()
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 |
true if network connectivity exists or is in the process
of being established, false otherwise.
|
isFailover
boolean isFailover ()
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 |
true if this is a failover attempt, false
otherwise.
|
isRoaming
boolean isRoaming ()
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 |
true if roaming is in effect, false otherwise.
|
toString
String toString ()
Returns a string representation of the object. In general, the
toString method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
| Returns | |
|---|---|
String |
a string representation of the object. |
writeToParcel
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. |
flags |
int: Additional flags about how the object should be written.
May be 0 or PARCELABLE_WRITE_RETURN_VALUE.
|
Interfaces
Classes
- CaptivePortal
- ConnectivityManager
- ConnectivityManager.NetworkCallback
- Credentials
- DhcpInfo
- IpPrefix
- LinkAddress
- LinkProperties
- LocalServerSocket
- LocalSocket
- LocalSocketAddress
- MailTo
- Network
- NetworkCapabilities
- NetworkInfo
- NetworkRequest
- NetworkRequest.Builder
- NetworkSpecifier
- Proxy
- ProxyInfo
- RouteInfo
- SSLCertificateSocketFactory
- SSLSessionCache
- TrafficStats
- Uri
- Uri.Builder
- UrlQuerySanitizer
- UrlQuerySanitizer.IllegalCharacterValueSanitizer
- UrlQuerySanitizer.ParameterValuePair
- VpnService
- VpnService.Builder
Enums
Exceptions
Follow Google Developers on WeChat
Browse this site in ?
(Sep 2017 survey)


