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

此代碼對我的工作..