public class NetworkInfo extends Object implements Parcelable
Use ConnectivityManager.getActiveNetworkInfo()
to get an instance that represents
the current network connection.
Modifier and Type | Class and Description |
---|---|
static class |
NetworkInfo.DetailedState
The fine-grained state of a network connection.
|
static class |
NetworkInfo.State
Coarse-grained network state.
|
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<NetworkInfo> |
CREATOR |
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
NetworkInfo(int type,
int subtype,
String typeName,
String subtypeName) |
NetworkInfo(NetworkInfo source) |
Modifier and Type | Method and Description |
---|---|
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
NetworkInfo pertains. |
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 |
isMetered()
Returns if this network is metered.
|
boolean |
isRoaming()
Indicates whether the device is currently roaming on this network.
|
void |
setDetailedState(NetworkInfo.DetailedState detailedState,
String reason,
String extraInfo)
Sets the fine-grained state of the network.
|
void |
setExtraInfo(String extraInfo)
Set the extraInfo field.
|
void |
setFailover(boolean isFailover)
Set the failover boolean.
|
void |
setIsAvailable(boolean isAvailable)
Sets if the network is available, ie, if the connectivity is possible.
|
void |
setMetered(boolean isMetered) |
void |
setRoaming(boolean isRoaming) |
void |
setSubtype(int subtype,
String subtypeName) |
void |
setType(int type) |
String |
toString()
Returns a string representation of the object.
|
void |
writeToParcel(Parcel dest,
int flags)
Flatten this object in to a Parcel.
|
public static final Parcelable.Creator<NetworkInfo> CREATOR
public NetworkInfo(NetworkInfo source)
public int getType()
NetworkInfo
pertains.ConnectivityManager.TYPE_MOBILE
, ConnectivityManager.TYPE_WIFI
, ConnectivityManager.TYPE_WIMAX
, ConnectivityManager.TYPE_ETHERNET
, ConnectivityManager.TYPE_BLUETOOTH
, or other
types defined by ConnectivityManager
public void setType(int type)
public int getSubtype()
public void setSubtype(int subtype, String subtypeName)
public String getTypeName()
public String getSubtypeName()
public boolean isConnectedOrConnecting()
isConnected()
instead, which guarantees
that the network is fully usable.true
if network connectivity exists or is in the process
of being established, false
otherwise.public boolean isConnected()
Always call this before attempting to perform data transactions.
true
if network connectivity exists, false
otherwise.public boolean isAvailable()
true
if the network is available, false
otherwisepublic void setIsAvailable(boolean isAvailable)
isAvailable
- the new availability value.public boolean isFailover()
true
if this is a failover attempt, false
otherwise.public void setFailover(boolean isFailover)
isFailover
- true
to mark the current connection attempt
as a failover.public boolean isRoaming()
true
, it suggests that use of data on this network
may incur extra costs.true
if roaming is in effect, false
otherwise.public void setRoaming(boolean isRoaming)
public boolean isMetered()
true
if large transfers should be avoided, otherwise
false
.public void setMetered(boolean isMetered)
public NetworkInfo.State getState()
public NetworkInfo.DetailedState getDetailedState()
public void setDetailedState(NetworkInfo.DetailedState detailedState, String reason, String extraInfo)
detailedState
- the NetworkInfo.DetailedState
.reason
- a String
indicating the reason for the state change,
if one was supplied. May be null
.extraInfo
- an optional String
providing addditional network state
information passed up from the lower networking layers.public void setExtraInfo(String extraInfo)
extraInfo
- an optional String
providing addditional network state
information passed up from the lower networking layers.public String getReason()
public String getExtraInfo()
public String toString()
Object
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())
public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel dest, int flags)
Parcelable
writeToParcel
in interface Parcelable
dest
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.