Android
android.net
public class

android.net.NetworkConnectivityListener

java.lang.Object
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

            NetworkConnectivityListener()
Create a new NetworkConnectivityListener.

Public Methods

          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.
  synchronized        void  startListening(Context context)
This method starts listening for network connectivity state changes.
  synchronized        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

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.

Returns

  • NetworkInfo

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.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48