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

发布于 2024-12-05 09:54:15 字数 160 浏览 2 评论 0原文

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

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

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

I have developed an application for blackberry devices. The application is working fine if it uses internet via data service provider.

I have BB 9550 and I want to use my application using wifi. I tried a lot but I cant get proper answer to check wifi condition.

How we can differentiate to run our application for wifi or data service provider?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀梦 2024-12-12 09:54:15

要检查 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();

希望这会帮助你

For checking wifi is connected or not the following method will help you.

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

if wifi is not connected the following methods will help to add data service.

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

Example to use above methods.

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

Hope This will help you

没有心的人 2024-12-12 09:54:15

试试这个:

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();

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

And when you need to connect, you'll have to add the parameters to the URL:

yourUrl = yourUrl + getParameters();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文