Pramodhini
Pramodhini

Reputation: 37

blackberry app not running on gprs connection in device

Hi am trying to run my app on blackberry device using Edge gprs connection but its not rendering the pages.i have tried lot to get the connection,also i tried the various links to solve, one of the simple code i have attached here, kindly guide me to solve this

 public static String getConnectionString() { 

      String value="" ;

        if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
        {
           value=";interface=wifi";
        }else{
            value=";deviceside=true";
        }

        return value; 
    }

Upvotes: 1

Views: 444

Answers (1)

Solution
Solution

Reputation: 602

Append the connection string to your url. Then try

public static String getConnectionString() {

    // This code is based on the connection code developed by Mike Nelson of
    // AccelGolf.
    // http://blog.accelgolf.com/2009/05/22/blackberry-cross-carrier-and-cross-network-http-connection
    String connectionString = null;

    // Simulator behavior is controlled by the USE_MDS_IN_SIMULATOR
    // variable.
    if (DeviceInfo.isSimulator()) {

        connectionString = ";deviceSide=true";
    }

    // Wifi is the preferred transmission method
    else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
      //   System.out.println("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) {
      // System.out.println("Carrier coverage.---->>" + CoverageInfo.getCoverageStatus());

        String carrierUid = getCarrierBIBSUid();
      //  DebugScreen.Log(" carrierUid is: " + carrierUid);
        if (carrierUid == null) {
            // Has carrier coverage, but not BIBS. So use the carrier's TCP
            // network
            // System.out.println("No Uid");
            String wapString = getAvailableConnectionsString();
        //  DebugScreen.Log("from wap2 connection--->" + wapString);
            if(wapString == null){
            connectionString = ";deviceside=true";
            }else{
                connectionString = wapString;
            }
        } else {
            // otherwise, use the Uid to construct a valid carrier BIBS
            // request

            connectionString = ";deviceside=true;connectionUID=" + carrierUid + ";ConnectionType=mds-public";
        }
    }

    // Check for an MDS connection instead (BlackBerry Enterprise Server)
    else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {
        // System.out.println("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) {
        // System.out.println("There is no available connection.");
    }

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

    return connectionString;
}

Add this method and append connection String to url.

 private static String getCarrierBIBSUid() {

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

    for (currentRecord = 0; currentRecord < records.length; currentRecord++) {
  //    DebugScreen.Log("Util.getCarrierBIBSUid() for ippp--------->>" + records[currentRecord].getCid().toLowerCase());
        if (records[currentRecord].getCid().toLowerCase().equals("ippp")) {
   //       DebugScreen.Log("Util.getCarrierBIBSUid() for bibs..........'''''" + records[currentRecord].getName().toLowerCase().indexOf("bibs") );
            if (records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0) {
                return records[currentRecord].getUid();
            }
        }

    }

    return null;
}


    public static String getAvailableConnectionsString() {
    String conns = null;
    ServiceBook sb = ServiceBook.getSB();
    ServiceRecord[] records = sb.getRecords();

    String cid;
    String uid;
    for (int i = 0; i < records.length; i++) {
        ServiceRecord myRecord = records[i];
        // System.out.println("record name:"+myRecord.getName()+"  cid:"+myRecord.getCid().toLowerCase()+" "+myRecord.getUid().toLowerCase());
        if (myRecord.isValid() && !myRecord.isDisabled()) {
            cid = myRecord.getCid().toLowerCase();
            uid = myRecord.getUid().toLowerCase();

            //Wap2.0
            if (cid.indexOf("wptcp") != -1 && uid.indexOf("wifi") == -1 && uid.indexOf("mms") == -1 ) {
                conns = ";deviceside=true" + ";ConnectionUID="+ myRecord.getUid();
                if(myRecord.getUid().equalsIgnoreCase("GTCP BIBS")){
                    return conns;
                }
            }

        }
    }

    return conns;
}

This code is work for me..

Upvotes: 2

Related Questions