Checking for all possible Internet providers - Android Network

Android examples for Network:Internet

Description

Checking for all possible Internet providers

Demo Code


//package com.java2s;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    /**/*w ww  .j a  v a  2  s.  c  o  m*/
     * Checking for all possible Internet providers
     * **/

    public static Boolean isNetworkAvailable(Context context) {

        Boolean isConnected = false;

        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        if (connectivityManager != null) {
            NetworkInfo[] networkInfo = connectivityManager
                    .getAllNetworkInfo();
            if (networkInfo != null) {
                for (int index = 0; index < networkInfo.length; index++) {
                    if (networkInfo[index].isConnected()) {
                        isConnected = true;
                        break;
                    }
                }
            }
        }
        return isConnected;
    }
}

Related Tutorials