Search in sources :

Example 6 with ConnectivityManager

use of android.net.ConnectivityManager in project AnimeTaste by daimajia.

the class NetworkUtils method isWifiConnected.

/**
	 * make true current connect service is wifi
	 * 
	 * @param mContext
	 * @return
	 */
public static boolean isWifiConnected(Context mContext) {
    ConnectivityManager connManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWifi.isConnected()) {
        return true;
    } else {
        return false;
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 7 with ConnectivityManager

use of android.net.ConnectivityManager in project android by cSploit.

the class Network method isWifiConnected.

public static boolean isWifiConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return info != null && info.isConnected() && info.isAvailable();
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 8 with ConnectivityManager

use of android.net.ConnectivityManager in project android by cSploit.

the class Network method isConnectivityAvailable.

public static boolean isConnectivityAvailable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    return info != null && info.isConnected();
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 9 with ConnectivityManager

use of android.net.ConnectivityManager in project android-app by eoecn.

the class APNManager method getDefaultNetworkType.

public int getDefaultNetworkType() {
    int networkType = -1;
    ConnectivityManager connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
    } else {
        // wifi network have priority
        NetworkInfo wifiNetworkInfo = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiNetworkInfo != null && wifiNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
            return ConnectivityManager.TYPE_WIFI;
        }
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        for (int i = 0; i < info.length; i++) {
            if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                // use first available network
                networkType = info[i].getType();
                break;
            }
        }
    }
    return networkType;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 10 with ConnectivityManager

use of android.net.ConnectivityManager in project android-app by eoecn.

the class NetWorkHelper method isWifiDataEnable.

/**
	 * 判断wifi 是否可用
	 * @param context
	 * @return
	 * @throws Exception
	 */
public static boolean isWifiDataEnable(Context context) throws Exception {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean isWifiDataEnable = false;
    isWifiDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
    return isWifiDataEnable;
}
Also used : ConnectivityManager(android.net.ConnectivityManager)

Aggregations

ConnectivityManager (android.net.ConnectivityManager)361 NetworkInfo (android.net.NetworkInfo)258 Context (android.content.Context)15 TelephonyManager (android.telephony.TelephonyManager)13 RemoteException (android.os.RemoteException)11 Test (org.junit.Test)11 Intent (android.content.Intent)10 WifiManager (android.net.wifi.WifiManager)9 Method (java.lang.reflect.Method)9 Network (android.net.Network)8 IOException (java.io.IOException)8 PackageManager (android.content.pm.PackageManager)7 SharedPreferences (android.content.SharedPreferences)6 NetworkCapabilities (android.net.NetworkCapabilities)6 UserManager (android.os.UserManager)6 Activity (android.app.Activity)5 ApplicationInfo (android.content.pm.ApplicationInfo)5 IPackageManager (android.content.pm.IPackageManager)5 PackageInfo (android.content.pm.PackageInfo)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5