WIMM Labs


com.wimm.framework.service
Class NetworkService

java.lang.Object
  extended by com.wimm.framework.service.NetworkService

public class NetworkService
extends Object

The NetworkService class provides an interface for requesting a network connection.

Start by registering for the ACTION_NETWORK_AVAILABLE and ACTION_NETWORK_TAKEDOWN intents and calling requestNetworkConnection(). If the service is able to bring up a network connection it broadcasts the ACTION_NETWORK_AVAILABLE intent. If the network connection can not be brought up, the service will broadcast the ACTION_NETWORK_FAILURE intent with an error code.

Once the network connection is established, the service sends a ACTION_NETWORK_TAKEDOWN intent at regular intervals. On receiving a ACTION_NETWORK_TAKEDOWN, call postponeNetworkTakedown() if the network connection is still needed.

The service will take down the network connection if no listeners call postponeNetworkTakedown().

Note: postponeNetworkTakedown() requests may not be honored in all cases. This depends on the length of time the connection has been up and battery/charging state.

Use of this class requires the "com.wimm.permission.NETWORK" permission.

Refer to WIMM Developer's Guide on network HOWTO guide for more information about WIMM Network connection.

Since:
WIMM SDK 1.0.0

Nested Class Summary
static class NetworkService.Error
          Values returned in the extra EXTRA_ERROR.
 
Field Summary
static String ACTION_NETWORK_AVAILABLE
          Intent broadcast when the network connection is available.
static String ACTION_NETWORK_FAILURE
          Intent broadcast when a network connection request fails.
static String ACTION_NETWORK_TAKEDOWN
          Intent broadcast when the system is ready to close the network connection.
static String EXTRA_ERROR
          An int extra in ACTION_NETWORK_FAILURE containing the failure reason.
 
Constructor Summary
NetworkService(Context context)
          Instantiates a new network service.
 
Method Summary
 boolean isNetworkAvailable()
          Checks if the network connection is available.
 void postponeNetworkTakedown()
          Request that the network connection remain open.
 void requestNetworkConnection()
          Requests a network connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_NETWORK_AVAILABLE

public static final String ACTION_NETWORK_AVAILABLE
Intent broadcast when the network connection is available.

This is a sticky broadcast.

Since:
WIMM SDK 1.0.0
See Also:
requestNetworkConnection(), Constant Field Values

ACTION_NETWORK_FAILURE

public static final String ACTION_NETWORK_FAILURE
Intent broadcast when a network connection request fails. Broadcast to registered receivers only.

May include the following extras:

EXTRA_ERROR containing the failure reason.

Since:
WIMM SDK 1.0.3
See Also:
requestNetworkConnection(), Constant Field Values

ACTION_NETWORK_TAKEDOWN

public static final String ACTION_NETWORK_TAKEDOWN
Intent broadcast when the system is ready to close the network connection. Broadcast to registered receivers only.

Since:
WIMM SDK 1.0.0
See Also:
postponeNetworkTakedown(), Constant Field Values

EXTRA_ERROR

public static final String EXTRA_ERROR
An int extra in ACTION_NETWORK_FAILURE containing the failure reason.

Possible values are listed in NetworkService.Error.

Since:
WIMM SDK 1.0.3
See Also:
Constant Field Values
Constructor Detail

NetworkService

public NetworkService(Context context)
Instantiates a new network service.

Parameters:
context - The Context.
Since:
WIMM SDK 1.0.0
Method Detail

requestNetworkConnection

public void requestNetworkConnection()
Requests a network connection.

Since:
WIMM SDK 1.0.0

postponeNetworkTakedown

public void postponeNetworkTakedown()
Request that the network connection remain open. This method should be called after receiving ACTION_NETWORK_TAKEDOWN.

Since:
WIMM SDK 1.0.0

isNetworkAvailable

public boolean isNetworkAvailable()
Checks if the network connection is available.

Returns:
true if the network connection is available.
Since:
WIMM SDK 1.0.0

WIMM Labs