开发者

wireless problem in android

I have to check wireless network enabled or disabled in android. How to do that?

I have to check this one.(setting->location & security->use wireless networks) not in the(Settings -> Wireless & network settings -> wifi). I tried for second one.

In the coding even though I on the air plane mode it is shown Internet Connection Present. So I have to check wireless in setting->location & security->use wireless networks.

my code:

 private boolean checkInternetConnection() {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        // test for connection
        if (cm.getActiveNetworkInfo() != null
                && cm.getActiveNetworkInfo().isAvailable()
                && cm.getActiveNetworkInfo().isConnected()) {
开发者_高级运维            Log.e("TAG", "Internet Connection Present");
            return true;
        } else {
            Log.e("TAG", "Internet Connection Not Present");
            return false;
        }
    }

please assist me.


private boolean connectionAvailable() {
    boolean connected = false;
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
            connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
        //we are connected to a network
        connected = true;
    }
    return connected;
}


If you want to check (setting->location & security->use wireless networks) then you have to check this condition

private boolean connectionAvailable() {
    boolean connected = false;
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
            connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
        //we are connected to a network
        connected = true;
    }
    return connected;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜