黑莓应用程序没有在设备上的gprs连接上运行

时间:2012-10-19 06:48:35

标签: blackberry blackberry-simulator blackberry-eclipse-plugin blackberry-jde blackberry-webworks

我正在尝试使用Edge gprs连接在黑莓设备上运行我的应用程序,但它没有渲染pages.i已经尝试了很多连接,我也尝试了各种链接来解决,我附加的简单代码之一在这里,请指导我解决这个问题

 public static String getConnectionString() { 

      String value="" ;

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

        return value; 
    }

1 个答案:

答案 0 :(得分:2)

将连接字符串附加到您的网址。然后尝试

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;
}

添加此方法并将连接字符串追加到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;
}

这段代码对我有用..

相关问题