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.
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:
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:
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 HttpRequestDispatcher.java:import net.rim.device.api.system.CoverageInfo;
The new connection code for HttpRequestDispatcher’s run method to attempt connections in the given order follows:String connectionParameters = "";
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.
BLACKBERRY Related Interview Questions
|J2ME Interview Questions||BLACKBERRY Interview Questions|
|Android Interview Questions||Retail Interview Questions|
|Telecommunication Project Management Interview Questions||Mobile Testing Interview Questions|
|Telemarketing Interview Questions||Mobile Application Testing Interview Questions|
|Mobile Marketing Interview Questions||Telecom Billing Interview Questions|
|Mobile Application Architect Interview Questions|
Setting The Stage
What Makes A Blackberry Application?
User Interface Basics
Beyond The Basics Of User Interfaces
Hello Out There! Making A Network-enabled Application
Where Am I? Using Location-based Services
Getting Your App Out There: Packaging And Publishing
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.