代码之家  ›  专栏  ›  技术社区  ›  Riddhi Barbhaya

黑莓GPRS不工作

  •  1
  • Riddhi Barbhaya  · 技术社区  · 12 年前

    我有一个黑莓应用程序,运行非常好的无线网络。但我无法使用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");
    }
    
    1 回复  |  直到 12 年前
        1
  •  1
  •   Nate    12 年前

    您需要将连接类型附加在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;
    }
    

    一旦你写了这个代码。使用

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

    它将确定可用的网络类型。