Build 1.0_r1(from source)

android.net
Class NetworkConnectivityListener

java.lang.Object
  extended by android.net.NetworkConnectivityListener

public class NetworkConnectivityListener
extends Object

A wrapper for a broadcast receiver that provides network connectivity state information, independent of network type (mobile, Wi-Fi, etc.).


Nested Class Summary
static class NetworkConnectivityListener.State
           
 
Constructor Summary
NetworkConnectivityListener()
          Create a new NetworkConnectivityListener.
 
Method Summary
 NetworkInfo getNetworkInfo()
          Return the NetworkInfo associated with the most recent connectivity event.
 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.
 String getReason()
          An optional reason for the connectivity state change may have been supplied.
 NetworkConnectivityListener.State getState()
           
 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.
 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.
 void startListening(Context context)
          This method starts listening for network connectivity state changes.
 void stopListening()
          This method stops this class from listening for network changes.
 void unregisterHandler(Handler target)
          This methods unregisters the specified Handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetworkConnectivityListener

public NetworkConnectivityListener()
Create a new NetworkConnectivityListener.

Method Detail

startListening

public void startListening(Context context)
This method starts listening for network connectivity state changes.

Parameters:
context -

stopListening

public void stopListening()
This method stops this class from listening for network changes.


registerHandler

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.

unregisterHandler

public void unregisterHandler(Handler target)
This methods unregisters the specified Handler.

Parameters:
target -

getState

public NetworkConnectivityListener.State getState()

getNetworkInfo

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.

getOtherNetworkInfo

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.

Returns:
NetworkInfo

isFailover

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.

getReason

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.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature