Friday, July 6, 2012

Blackberry Reliable Network Connection

Now a day so many application require to establish network connection In Blackberry there are no simple way to pass only URL and get connection. In blackberry there are more then Five type of connection available. Developer have to confirm which connection available so that can use on application. On Blackberry developer have to pass suffix after URL if device have wifi connection available then "interface=wifi" suffix is use.

Following Type of Connection available:

1. Blackberry Enterprise server using Blackberry Mobile Data System(MSD)

2. Blackberry Internet Service

3. Wireless(WiFi)

4. WAP 1.x

5. WAP 2.0

There are lot of problem when you establish connection on blackberry following example will resolve most of connection problem.


* Determines what connection type to use and returns the necessary string
* to use it.
* @return A string with the connection info

private String getConnectionString() {

// This code is based on the connection code developed by Mike Nelson of AccelGolf.

String connectionString = null;
// Simulator behavior is controlled by the USE_MDS_IN_SIMULATOR
// variable.

if (DeviceInfo.isSimulator()) {

    logMessage("Device is a simulator and USE_MDS_IN_SIMULATOR is false");
    connectionString = ";deviceside=true";

// Wifi is the preferred transmission method

else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
    logMessage("Device is connected via Wifi.");
    connectionString = ";interface=wifi";

// Is the carrier network the only way to connect?
else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) ==  CoverageInfo.COVERAGE_DIRECT) {
    logMessage("Carrier coverage.");

String carrierUid = getCarrierBIBSUid();

if (carrierUid == null) {
// Has carrier coverage, but not BIBS. So use the carrier's TCP  network
    logMessage("No Uid");
    connectionString = ";deviceside=true";
} else {
// otherwise, use the Uid to construct a valid carrier BIBS request
    logMessage("uid is: " + carrierUid);
    connectionString = ";deviceside=false;connectionUID="+ carrierUid + ";ConnectionType=mds-public";


// Check for an MDS connection instead (BlackBerry Enterprise Server)

else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {

    logMessage("MDS coverage found");
    connectionString = ";deviceside=false";

// If there is no connection available abort to avoid bugging the user unnecssarily.
else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) {
    logMessage("There is no available connection.");

// In theory, all bases are covered so this shouldn't be reachable.
else {
    logMessage("no other options found, assuming device.");
    connectionString = ";deviceside=true";
return connectionString;


* Looks through the phone's service book for a carrier provided BIBS
* network
* @return The uid used to connect to that network.
private static String getCarrierBIBSUid() {

    ServiceRecord[] records = ServiceBook.getSB().getRecords();
    int currentRecord;

   for (currentRecord = 0; currentRecord < records.length; currentRecord++) {
     if (records[currentRecord].getCid().toLowerCase().equals("ippp")) {
      if (records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0) {
        return records[currentRecord].getUid();




return null;

private void logMessage(String msg){

Help and Source from:

No comments:

Post a Comment