Search in sources :

Example 26 with NetworkInfo

use of android.net.NetworkInfo in project android-common by Trinea.

the class NetWorkUtils method getNetworkType.

/**
     * Get network type
     * 
     * @param context
     * @return
     */
public static int getNetworkType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager == null ? null : connectivityManager.getActiveNetworkInfo();
    return networkInfo == null ? -1 : networkInfo.getType();
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 27 with NetworkInfo

use of android.net.NetworkInfo in project android-common by Trinea.

the class NetWorkUtils method getNetworkTypeName.

/**
     * Get network type name
     * 
     * @param context
     * @return
     */
public static String getNetworkTypeName(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo;
    String type = NETWORK_TYPE_DISCONNECT;
    if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
        return type;
    }
    ;
    if (networkInfo.isConnected()) {
        String typeName = networkInfo.getTypeName();
        if ("WIFI".equalsIgnoreCase(typeName)) {
            type = NETWORK_TYPE_WIFI;
        } else if ("MOBILE".equalsIgnoreCase(typeName)) {
            String proxyHost = android.net.Proxy.getDefaultHost();
            type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP;
        } else {
            type = NETWORK_TYPE_UNKNOWN;
        }
    }
    return type;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 28 with NetworkInfo

use of android.net.NetworkInfo in project MVCHelper by LuckyJayce.

the class NetworkUtils method hasNetwork.

/**
	 * 是否有网络连接
	 * 
	 * @param paramContext
	 * @return
	 */
public static boolean hasNetwork(Context paramContext) {
    try {
        ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
        if ((localNetworkInfo != null) && (localNetworkInfo.isAvailable()))
            return true;
    } catch (Throwable localThrowable) {
        localThrowable.printStackTrace();
    }
    return false;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 29 with NetworkInfo

use of android.net.NetworkInfo in project MVCHelper by LuckyJayce.

the class NetworkUtils method isWifi.

/**
	 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
	 * 
	 * @param context
	 * @return
	 */
public static boolean isWifi(Context context) {
    ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectMgr.getActiveNetworkInfo();
    if (info == null)
        return false;
    return info.getType() == ConnectivityManager.TYPE_WIFI;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 30 with NetworkInfo

use of android.net.NetworkInfo in project Signal-Android by WhisperSystems.

the class MmsRadio method isConnected.

private boolean isConnected() {
    NetworkInfo info = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
    Log.w("MmsRadio", "Connected: " + info);
    if ((info == null) || (info.getType() != TYPE_MOBILE_MMS) || !info.isConnected())
        return false;
    return true;
}
Also used : NetworkInfo(android.net.NetworkInfo)

Aggregations

NetworkInfo (android.net.NetworkInfo)489 ConnectivityManager (android.net.ConnectivityManager)257 Intent (android.content.Intent)44 LinkProperties (android.net.LinkProperties)38 NetworkState (android.net.NetworkState)26 Test (org.junit.Test)24 PendingIntent (android.app.PendingIntent)22 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)6 SharedPreferences (android.content.SharedPreferences)6