检查Blackberry应用程序中的wifi状况

我开发了一个黑莓设备的应用程序.如果它通过数据服务提供商使用互联网,该应用程序正常工作.

我有BB 9550,我想使用我的应用程序使用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();

希望对你有帮助

相关文章
相关标签/搜索