Search in sources :

Example 61 with NetworkInfo

use of android.net.NetworkInfo in project k-9 by k9mail.

the class Utility method hasConnectivity.

/**
     * Check to see if we have network connectivity.
     */
public static boolean hasConnectivity(final Context context) {
    final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null) {
        return false;
    }
    final NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
    if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) {
        return true;
    } else {
        return false;
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 62 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)

Example 63 with NetworkInfo

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

the class OutgoingLegacyMmsConnection method isConnectionPossible.

public static boolean isConnectionPossible(Context context) {
    try {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getNetworkInfo(MmsRadio.TYPE_MOBILE_MMS);
        if (networkInfo == null) {
            Log.w(TAG, "MMS network info was null, unsupported by this device");
            return false;
        }
        getApn(context);
        return true;
    } catch (ApnUnavailableException e) {
        Log.w(TAG, e);
        return false;
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 64 with NetworkInfo

use of android.net.NetworkInfo in project Klyph by jonathangerbaud.

the class ConnectionState method isOnline.

public boolean isOnline() {
    try {
        connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        connected = networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
        return connected;
    } catch (Exception e) {
        Log.v("connectivity", e.toString());
    }
    return connected;
}
Also used : NetworkInfo(android.net.NetworkInfo)

Example 65 with NetworkInfo

use of android.net.NetworkInfo in project Klyph by jonathangerbaud.

the class ConnectionState method isOnline.

public Boolean isOnline() {
    try {
        connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        connected = networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
        return connected;
    } catch (Exception e) {
        Log.v("connectivity", e.toString());
    }
    return connected;
}
Also used : NetworkInfo(android.net.NetworkInfo)

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