Monitoring Network Details

The Connectivity Manager provides a high-level view of the available network connections. Using the getActiveNetworkInfo or getNetworkInfo methods, as shown in Listing 13-14, returns NetworkInfo objects that include details on the currently active network or on an inactive network of the type specified.

Use the returned NetworkInfo details to find the connection status, network type, and detailed state information of the returned network.

STING 13-14: Accessing network information

// Get the active network information.

NetworkInfo activeNetwork = connectivity.getActiveNetworkInfo(); int networkType = networkInfo.getType(); switch (networkType) {

case (ConnectivityManager.TYPE_MOBILE) : break; case (ConnectivityManager.TYPE_WIFI) : break; default: break;

// Get the mobile network information. int network = ConnectivityManager.TYPE_MOBILE;

NetworkInfo mobileNetwork = connectivity.getNetworkInfo(network);

Available for download on

Networklnfo.State state = mobileNetwork.getState();

Networklnfo.DetailedState detailedState = mobileNetwork.getDetailedState();

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide

Post a comment