检查无线条件在黑莓应用程序



我为黑莓设备开发了一个应用程序。如果应用程序通过数据服务提供商使用互联网,则可以正常工作。

我有BB 9550,我想使用wifi使用我的应用程序。我试了很多次,但我无法得到正确的答案来检查wifi状况。

我们如何区分为wifi或数据服务提供商运行我们的应用程序?

检查wifi是否连接,以下方法将帮助您。

 public static boolean isWifiConnected()
    {
        try
        {
            if (RadioInfo.getSignalLevel(RadioInfo.WAF_WLAN) != RadioInfo.LEVEL_NO_COVERAGE)
            {
                return true;
            }
        }
        catch(Exception e)
        {
            System.out.println("Exception during get WiFi status");
        }
        return false;
    } 

如果未连接wifi,可以使用以下方法添加数据服务。

public static String getConnParam(){
        String connectionParameters = "";
        if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
        // Connected to a WiFi access point
        connectionParameters = ";interface=wifi";
        } else {
        int coverageStatus = CoverageInfo.getCoverageStatus();
        ServiceRecord record = getWAP2ServiceRecord();
        if (record != null
        && (coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
        CoverageInfo.COVERAGE_DIRECT) {
        // Have network coverage and a WAP 2.0 service book record
        connectionParameters = ";deviceside=true;ConnectionUID="
        + record.getUid();
        } else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) ==
        CoverageInfo.COVERAGE_MDS) {
        // Have an MDS service book and network coverage
        connectionParameters = ";deviceside=false";
        } else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
        CoverageInfo.COVERAGE_DIRECT) {
        // Have network coverage but no WAP 2.0 service book record
        connectionParameters = ";deviceside=true";
        }
    }
        return connectionParameters;
    }
        private static  ServiceRecord getWAP2ServiceRecord() {
            ServiceBook sb = ServiceBook.getSB();
            ServiceRecord[] records = sb.getRecords();
            for(int i = 0; i < records.length; i++) {
            String cid = records[i].getCid().toLowerCase();
            String uid = records[i].getUid().toLowerCase();
            if (cid.indexOf("wptcp") != -1 &&
            uid.indexOf("wifi") == -1 &&
            uid.indexOf("mms") == -1) {
            return records[i];
            }
            }
            return null;
            }

使用上述方法的示例。

String connParams=(isWifiConnected())?";interface=wifi":getConnParam();

希望这对你有帮助

try this:

private static String getParameters() {
    if (GetWiFiCoverageStatus()) {
        return ";deviceside=true;interface=wifi";
    }
    else {
        return yourParametersForEdge
    }
}
private static boolean GetWiFiCoverageStatus()  {
    if((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)) {
        return true;
    } 
    else 
        return false;           
}

当你需要连接时,你必须将参数添加到URL:

yourUrl = yourUrl + getParameters();

相关内容

最新更新