Search in sources :

Example 66 with ConnectivityManager

use of android.net.ConnectivityManager in project carat by amplab.

the class SamplingLibrary method getNetworkType.

/**
	 * Get the network type, for example Wifi, mobile, wimax, or none.
	 * 
	 * @param context
	 * @return
	 */
public static String getNetworkType(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm == null)
        return TYPE_UNKNOWN;
    NetworkInfo i = cm.getActiveNetworkInfo();
    if (i == null)
        return TYPE_UNKNOWN;
    return i.getTypeName();
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 67 with ConnectivityManager

use of android.net.ConnectivityManager in project FileDownloader by lingochamp.

the class FileDownloadUtils method isNetworkOnWifiType.

public static boolean isNetworkOnWifiType() {
    final ConnectivityManager manager = (ConnectivityManager) FileDownloadHelper.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo info = manager.getActiveNetworkInfo();
    return info != null && info.getType() == ConnectivityManager.TYPE_WIFI;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 68 with ConnectivityManager

use of android.net.ConnectivityManager in project KJFrameForAndroid by kymjs.

the class SystemTool method isWiFi.

/**
     * 判断是否为wifi联网
     */
public static boolean isWiFi(Context cxt) {
    ConnectivityManager cm = (ConnectivityManager) cxt.getSystemService(Context.CONNECTIVITY_SERVICE);
    // wifi的状态:ConnectivityManager.TYPE_WIFI
    // 3G的状态:ConnectivityManager.TYPE_MOBILE
    State state = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    return State.CONNECTED == state;
}
Also used : ConnectivityManager(android.net.ConnectivityManager) State(android.net.NetworkInfo.State)

Example 69 with ConnectivityManager

use of android.net.ConnectivityManager in project KJFrameForAndroid by kymjs.

the class SystemTool method checkNet.

/**
     * 判断网络是否连接
     */
public static boolean checkNet(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    // 网络是否连接
    return info != null;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 70 with ConnectivityManager

use of android.net.ConnectivityManager in project Lazy by l123456789jy.

the class MiscUtils method getAPN.

/**
     *
     * @param context  上下文
     * @return  apn
     */
public static String getAPN(Context context) {
    String apn = "";
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    if (info != null) {
        if (ConnectivityManager.TYPE_WIFI == info.getType()) {
            apn = info.getTypeName();
            if (apn == null) {
                apn = "wifi";
            }
        } else {
            apn = info.getExtraInfo().toLowerCase();
            if (apn == null) {
                apn = "mobile";
            }
        }
    }
    return apn;
}
Also used : NetworkInfo(android.net.NetworkInfo) 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