Search in sources :

Example 81 with ConnectivityManager

use of android.net.ConnectivityManager in project QLibrary by DragonsQC.

the class NetStateUtils method isNetworkConnected.

/**
     * 判断是否有网络连接
     *
     * @return 是否有网络连接
     */
public static boolean isNetworkConnected(Context context) {
    if (context != null) {
        ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
        if (mNetworkInfo != null) {
            return mNetworkInfo.isAvailable();
        }
    }
    return false;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 82 with ConnectivityManager

use of android.net.ConnectivityManager in project CloudReader by youlookwhat.

the class CheckNetwork method isNetworkConnected.

/**
     * 判断网络是否连通
     */
public static boolean isNetworkConnected(Context context) {
    try {
        if (context != null) {
            @SuppressWarnings("static-access") ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
            NetworkInfo info = cm.getActiveNetworkInfo();
            return info != null && info.isConnected();
        } else {
            /**如果context为空,就返回false,表示网络未连接*/
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 83 with ConnectivityManager

use of android.net.ConnectivityManager in project CloudReader by youlookwhat.

the class CheckNetwork method isNetworkConnected.

/**
     * 判断网络是否连通
     */
public static boolean isNetworkConnected(Context context) {
    try {
        if (context != null) {
            @SuppressWarnings("static-access") ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
            NetworkInfo info = cm.getActiveNetworkInfo();
            return info != null && info.isConnected();
        } else {
            /**如果context为空,就返回false,表示网络未连接*/
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 84 with ConnectivityManager

use of android.net.ConnectivityManager in project CloudReader by youlookwhat.

the class CheckNetwork method isWifiConnected.

public static boolean isWifiConnected(Context context) {
    if (context != null) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getActiveNetworkInfo();
        return info != null && (info.getType() == ConnectivityManager.TYPE_WIFI);
    } else {
        /**如果context为null就表示为未连接*/
        return false;
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 85 with ConnectivityManager

use of android.net.ConnectivityManager in project android_frameworks_base by ResurrectionRemix.

the class NetworkManagementService method initDataInterface.

private void initDataInterface() {
    if (!TextUtils.isEmpty(mDataInterfaceName)) {
        return;
    }
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    LinkProperties linkProperties = cm.getLinkProperties(ConnectivityManager.TYPE_MOBILE);
    if (linkProperties != null) {
        mDataInterfaceName = linkProperties.getInterfaceName();
    }
}
Also used : ConnectivityManager(android.net.ConnectivityManager) LinkProperties(android.net.LinkProperties)

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