开发者

Network detection when on the London Underground

What is the best way to detect if a user has network service when a user has en开发者_如何学Pythontered the London Underground?

I've tried the following;

ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if(conMgr.getNetworkInfo(0).isAvailable() || conMgr.getNetworkInfo(1).isAvailable())
{
    // Application online
}

I've also tried getting the network level, but this seems to return the last level before the tube has entered the underground.

Any suggestions gratefully appreciated.


I'm using this code:

public boolean isOnline(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            return true;
        }

        return false;
    }

from thread How to check internet access on Android? InetAddress never times out

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜