Determining Network Availabilty BLACKBERRY

We’ve covered how to make network connections through various methods, but how do you determine which ones you can use? There are a couple of classes in the BlackBerry API that provide an easy way to do this.

Using CoverageInfo

The net.rim.device.api.system.CoverageInfo class enables you to determine which connection methods are currently available to the BlackBerry device. It looks at the device’s radio, current network coverage, and service book, and it provides information about what types of network connections are possible. The API for this class has changed somewhat between OS 4.2 and OS 4.5. We’ll cover the OS 4.5 version. The main method to determine coverage is the getCoverageStatus method.

The noparameter form of this method returns a bitmask of the different connection methods available over all physical network types (usually mobile network and WiFi, but also Bluetooth and USB connections to the computer if applicable). For example, if we called the method in an area with full network coverage on a device that’s activated on a BES and with a wireless service plan that allows direct TCP/IP access, we’d expect getCoverageStatus to return COVERAGE_MDS |COVERAGE_DIRECT | COVERAGE_BIS_B Note that the different COVERAGE values can each indicate several types of available connection methods:

  • COVERAGE_MDS means you can make connections using the BES/MDS connection method.
  • COVERAGE_DIRECT means you can make conections using direct TCP/IP or WAP.
  • COVERAGE_BIS_B means you can make connections sing BIS.

Using WLANInfo

The net.rim.device.api.system.WLANInfo class, available in OS 4.3 and later,lets you determine if you can make a direct WiFi connection. Usage of the class is easy. If the getWLANState method returns WLANInfo.WLAN_STATE_CONNECTED, then the device’s WiFi is turned on and connected to a wireless access point, and you can make direct WiFi connections.

Putting It All Together

We’ll modify our run method one last time to use CoverageInfo and WLANInfo to determine which connection methods are available and connect in our preferred order. For our application, we’ll look for available connection methods in the following order:

  • WiFi
  • WAP 2.0
  • Direct TCP/IP

We’ve left out BIS because it’s only available to approved applications, and we left out WAP 1.0 because it’s generally not recommended. Before we proceed with the code, remember to add the imports for WLANInfo and CoverageInfo to the top of

import net.rim.device.api.system.CoverageInfo;
import net.rim.device.api.system.WLANInfo;

The new connection code for HttpRequestDispatcher’s run method to attempt connections in the given order follows:

String connectionParameters = "";
// Connected to a WiFi access point
connectionParameters = ";interface=wifi";
} else {
int coverageStatus = CoverageInfo.getCoverageStatus();
ServiceRecord record = getWAP2ServiceRecord();
if (record != null
&& (coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
// Have network coverage and a WAP 2.0 service book record
connectionParameters = ";deviceside=true;ConnectionUID="
+ record.getUid();
} else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) ==
CoverageInfo.COVERAGE_MDS) {
// Have an MDS service book and network coverage
connectionParameters = ";deviceside=false";
} else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
// Have network coverage but no WAP 2.0 service book record
connectionParameters = ";deviceside=true";

The previous code will work with JDE 4.5 and higher. This is because of the use of CoverageInfo.COVERAGE_DIRECT, which replaced CoverageInfo.COVERAGE_CARRIER from JDE 4.5 and above. You can, however, make the code compile in all versions of the JDE 4.3 and higher by replacing CoverageInfo.COVERAGE_DIRECT with its constant value of 1, which is the same value that is used for CoverageInfo.COVERAGE_CARRIER in earlier JDE versions.

Notice that we have to check the service book to know if we should attempt a WAP 2.0 connection because CoverageInfo tells us only that the device has network coverage to the carrier, but CoverageInfo by itself can tell us if the device is able to connect via BES/MDS. It’s able to check both the network coverage and service book status. If you have a BlackBerry device that is WiFi capable, try running it with different combinations of WiFi and mobile network settings, such as turning either WiFi or the mobile network on or off.. You should be able to connect in a variety of configurations.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status