Search in sources :

Example 66 with NetworkInfo

use of android.net.NetworkInfo 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 67 with NetworkInfo

use of android.net.NetworkInfo 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 68 with NetworkInfo

use of android.net.NetworkInfo 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 69 with NetworkInfo

use of android.net.NetworkInfo 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 70 with NetworkInfo

use of android.net.NetworkInfo 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

NetworkInfo (android.net.NetworkInfo)511 ConnectivityManager (android.net.ConnectivityManager)274 Intent (android.content.Intent)47 LinkProperties (android.net.LinkProperties)38 NetworkState (android.net.NetworkState)26 Test (org.junit.Test)26 PendingIntent (android.app.PendingIntent)23 NetworkCapabilities (android.net.NetworkCapabilities)18 Network (android.net.Network)17 LargeTest (android.test.suitebuilder.annotation.LargeTest)17 RemoteException (android.os.RemoteException)16 Context (android.content.Context)15 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)15 WifiInfo (android.net.wifi.WifiInfo)13 Bundle (android.os.Bundle)13 TestUtils.mockNetworkInfo (com.squareup.picasso.TestUtils.mockNetworkInfo)12 IOException (java.io.IOException)11 WifiManager (android.net.wifi.WifiManager)9 IntentFilter (android.content.IntentFilter)8 BroadcastReceiver (android.content.BroadcastReceiver)7