android.net.NetworkConnectivityListener
A wrapper for a broadcast receiver that provides network connectivity
state information, independent of network type (mobile, Wi-Fi, etc.).
Nested Classes
Summary
Public Constructors
Public Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Constructors
public
NetworkConnectivityListener()
Create a new NetworkConnectivityListener.
Public Methods
public
NetworkInfo
getNetworkInfo()
Return the NetworkInfo associated with the most recent connectivity event.
Returns
NetworkInfo
for the network that had the most recent connectivity event.
public
NetworkInfo
getOtherNetworkInfo()
If the most recent connectivity event was a DISCONNECT, return
any information supplied in the broadcast about an alternate
network that might be available. If this returns a non-null
value, then another broadcast should follow shortly indicating
whether connection to the other network succeeded.
public
String
getReason()
An optional reason for the connectivity state change may have been supplied.
This returns it.
Returns
- the reason for the state change, if available, or
null
otherwise.
public
boolean
isFailover()
Returns true if the most recent event was for an attempt to switch over to
a new network following loss of connectivity on another network.
Returns
true
if this was a failover attempt, false
otherwise.
public
void
registerHandler(Handler target, int what)
This methods registers a Handler to be called back onto with the specified what code when
the network connectivity state changes.
Parameters
target
| The target handler. |
what
| The what code to be used when posting a message to the handler.
|
public
synchronized
void
startListening(Context context)
This method starts listening for network connectivity state changes.
public
synchronized
void
stopListening()
This method stops this class from listening for network changes.
public
void
unregisterHandler(Handler target)
This methods unregisters the specified Handler.