如何检查在黑莓SDK的活动的互联网连接? [英] How to check for an active internet connection in blackberry SDK?

查看:150
本文介绍了如何检查在黑莓SDK的活动的互联网连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何检查网络连接是否可用在黑莓应用程序?

How can we check internet connection is available or not in a blackberry application?

当我请求发送到我的服务器那个时候我想检查我的设备连接可用性。

When I send request to my server that time I want to check my device connection availability.

推荐答案

喜U可以测试这个code的连接。

Hi u can test your connection by this code.

public  static boolean isConnectionAvailable(String networkName) {
    HttpConnection connection;
    try {
        HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory("http://m.google.com");
        connection = httpConnectionFactory.makeConnectionUsing(networkName);
        if(connection == null)
            return false;
        else if (connection.getResponseCode() == HttpConnection.HTTP_OK) 
        {
            connection.close();
            return true;
        }
        connection.close();
    } catch( Exception e) {}

    return false;
}

这篇关于如何检查在黑莓SDK的活动的互联网连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆