Search in sources :

Example 51 with ConnectivityManager

use of android.net.ConnectivityManager in project FastDev4Android by jiangqqlmj.

the class JudgeNetWorker method getAPNType.

/**
     * @author jiangqq
     * 获取当前的网络状态  -1:没有网络  1:WIFI网络 2:wap网络 3:net网络
     * @param context
     * @return
     */
public static int getAPNType(Context context) {
    int netType = -1;
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo == null) {
        return netType;
    }
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_MOBILE) {
        Log.e("networkInfo.getExtraInfo()", "networkInfo.getExtraInfo() is " + networkInfo.getExtraInfo());
        if (networkInfo.getExtraInfo().toLowerCase().equals("cmnet")) {
            netType = CMNET;
        } else {
            netType = CMWAP;
        }
    } else if (nType == ConnectivityManager.TYPE_WIFI) {
        netType = WIFI;
    }
    return netType;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 52 with ConnectivityManager

use of android.net.ConnectivityManager in project FastDev4Android by jiangqqlmj.

the class JudgeNetWorker method checkConnectionOk.

public static boolean checkConnectionOk(Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
        return false;
    }
    return true;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 53 with ConnectivityManager

use of android.net.ConnectivityManager in project FastDev4Android by jiangqqlmj.

the class StrUtils method getAPNType.

public static int getAPNType(Context context) {
    int netType = -1;
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo == null) {
        return netType;
    }
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_MOBILE) {
        Log.e("networkInfo.getExtraInfo()", "networkInfo.getExtraInfo() is " + networkInfo.getExtraInfo());
        if (networkInfo.getExtraInfo().toLowerCase().equals("cmnet")) {
            netType = CMNET;
        } else {
            netType = CMWAP;
        }
    } else if (nType == ConnectivityManager.TYPE_WIFI) {
        netType = WIFI;
    }
    return netType;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) SuppressLint(android.annotation.SuppressLint)

Example 54 with ConnectivityManager

use of android.net.ConnectivityManager in project Talon-for-Twitter by klinker24.

the class Utils method hasInternetConnection.

public static boolean hasInternetConnection(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    return isConnected;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 55 with ConnectivityManager

use of android.net.ConnectivityManager in project Android-Developers-Samples by johnjohndoe.

the class MainActivity method checkNetworkConnection.

/**
     * Check whether the device is connected, and if so, whether the connection
     * is wifi or mobile (it could be something else).
     */
private void checkNetworkConnection() {
    // BEGIN_INCLUDE(connect)
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
    if (activeInfo != null && activeInfo.isConnected()) {
        wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
        mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
        if (wifiConnected) {
            Log.i(TAG, getString(R.string.wifi_connection));
        } else if (mobileConnected) {
            Log.i(TAG, getString(R.string.mobile_connection));
        }
    } else {
        Log.i(TAG, getString(R.string.no_wifi_or_mobile));
    }
// END_INCLUDE(connect)
}
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