1

我有一個黑莓應用程序與Wi-Fi完美運行良好。但我無法使用GPRS運行應用程序。請幫助me..Thanks ..黑莓GPRS不工作

boolean hasConnectivity_BIS = TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_BIS_B)&&TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_BIS_B); 
boolean hasConnectivity_MDS = TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_MDS)&&TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_MDS); 
boolean hasConnectivity_TCP_Cell = TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_TCP_CELLULAR)&&TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_TCP_CELLULAR); 
boolean hasConnectivity_TCP_wifi = TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_TCP_WIFI)&&TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_TCP_WIFI); 
boolean hasConnectivity_WAP = TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_WAP)&&TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_WAP); 
boolean hasConnectivity_WAP2 = TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_WAP2)&&TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_WAP2); 

if (hasConnectivity_BIS||hasConnectivity_MDS||hasConnectivity_TCP_Cell||hasConnectivity_TCP_wifi||hasConnectivity_WAP||hasConnectivity_WAP2) 
{ 
    boolean hasconn=ButtonPay.checkConnection(); 
    System.out.println("Has Connection?????>>> "+hasconn); 
    //my implementation  
} 
else 
{ 
    caller.showDialog("Response", "Internet connection not available"); 
} 
+0

你想要在GPRS上運行它。 –

+0

請在「ConnectionFactory」中配置傳輸類型的代碼以及超時。 –

回答

1

你需要你的URL後追加連接類型。

public static String getConnectionString() { 

    String connectionString = null; 

    // Simulator behaviour 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) { 

     connectionString = ";interface=wifi"; 
    } 

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

     String carrierUid = getCarrierBIBSUid(); 

     if (carrierUid == null) { 
      // Has carrier coverage, but not BIBS. So use the carrier's TCP 
      // network 

      connectionString = ";deviceside=true"; 
     } else { 
      // otherwise, use the Uid to construct a valid carrier BIBS 
      // request 

      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) { 

     connectionString = ";deviceside=false"; 
    } 

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

    } 

    // In theory, all bases are covered by now so this shouldn't be reachable.But hey, just in case ... 
    else { 

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

一旦你writtent此代碼。使用

con = (HttpConnection) Connector.open(url + getConnectionString()); 

它將確定可用的網絡類型。

+0

@Shanshak Agarwal ..謝謝很多..我試着這code.and很快回復你,也將接受解決方案,如果它的工作,我正在編輯我的代碼,請看它的代碼.. –

+2

這是傳統的方法並且不應該用於運行OS 5.0和更高版本的設備。相反,新的'ConnectionFactory'類更好,因爲它更容易使用,生成更清晰的代碼並且不太可能引入錯誤(無論是在編碼和執行中)。 –

+0

@ MisterSmith ..感謝回覆。但是我使用了這個代碼,因爲我想在OS 5.0上運行這個應用程序。我也會看到ConnectionFactory類。再次感謝。 –