Search in sources :

Example 31 with ConnectivityManager

use of android.net.ConnectivityManager in project weiciyuan by qii.

the class Utility method isWifi.

public static boolean isWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }
    }
    return false;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 32 with ConnectivityManager

use of android.net.ConnectivityManager in project weiciyuan by qii.

the class AboutFragment method buildContent.

private String buildContent() {
    String network = "";
    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            network = "Wifi";
        } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            int subType = networkInfo.getSubtype();
            if (subType == TelephonyManager.NETWORK_TYPE_GPRS) {
                network = "GPRS";
            }
        }
    }
    return "@四次元App #四次元App反馈# " + android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL + ",Android " + android.os.Build.VERSION.RELEASE + "," + network + " version:" + buildVersionInfo();
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 33 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 34 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 35 with ConnectivityManager

use of android.net.ConnectivityManager in project GeekNews by codeestX.

the class SystemUtil method isMobileNetworkConnected.

/**
     * 检查手机网络(4G/3G/2G)是否连接
     */
public static boolean isMobileNetworkConnected() {
    ConnectivityManager connectivityManager = (ConnectivityManager) App.getInstance().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mobileNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    return mobileNetworkInfo != null;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Aggregations

ConnectivityManager (android.net.ConnectivityManager)379 NetworkInfo (android.net.NetworkInfo)275 Context (android.content.Context)14 TelephonyManager (android.telephony.TelephonyManager)14 Intent (android.content.Intent)11 RemoteException (android.os.RemoteException)11 Test (org.junit.Test)11 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 UserManager (android.os.UserManager)7 SharedPreferences (android.content.SharedPreferences)6 NetworkCapabilities (android.net.NetworkCapabilities)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