1

您好我想在黑莓设备上运行我的应用程序使用Edge gprs连接,但它不呈现pages.i已经尝试了很多获得连接,我也试过各种链接来解决,我附上的简单代码之一,请引导我解决这个问题黑莓应用程序不运行gprs连接在设备

public static String getConnectionString() { 

     String value="" ; 

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

     return value; 
    } 
+0

删除此代码,并尝试 - ;装置侧=真 – Signare

+0

没有老板现在还站在它的启动画面上,没有得到inside.is东西存在净改变设备端的连接。 – Pramodhini

+0

检查我的答案 - http://stackoverflow.com/questions/12541805/httpconnection-not-working-in-real-device-blackberry/12541836#12541836 – Signare

回答

2

将连接字符串追加到您的url。然后尝试

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

此代码对我的工作..