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类。再次感谢。 –