开发者

how to test cell phone connectivity?

开发者 https://www.devze.com 2023-03-24 10:52 出处:网络
How to test network connection to tell if its a good signal or no signal? I would like to test this and do som开发者_JAVA技巧ething if the connectivity isn\'t good.

How to test network connection to tell if its a good signal or no signal? I would like to test this and do som开发者_JAVA技巧ething if the connectivity isn't good. I also would like to test for wifi connectivity.


This doesn't answer your question regarding whether it's a good connection or not, but this does figure out if it has a connection at all. Perhaps you can look at the objects in this method and see if it tells you more.

private boolean hasNetworkConnection() {
    boolean HaveConnectedWifi = false;
    boolean HaveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo)
    {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                HaveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                HaveConnectedMobile = true;
    }
    return HaveConnectedWifi || HaveConnectedMobile;
}
0

精彩评论

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