Search in sources :

Example 46 with NetworkInfo

use of android.net.NetworkInfo in project weiciyuan by qii.

the class Utility method isGprs.

public static boolean isGprs(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() != ConnectivityManager.TYPE_WIFI) {
            return true;
        }
    }
    return false;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 47 with NetworkInfo

use of android.net.NetworkInfo in project weiciyuan by qii.

the class Utility method isWifi.

public static boolean isWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }
    }
    return false;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 48 with NetworkInfo

use of android.net.NetworkInfo in project weiciyuan by qii.

the class AboutFragment method buildContent.

private String buildContent() {
    String network = "";
    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            network = "Wifi";
        } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            int subType = networkInfo.getSubtype();
            if (subType == TelephonyManager.NETWORK_TYPE_GPRS) {
                network = "GPRS";
            }
        }
    }
    return "@四次元App #四次元App反馈# " + android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL + ",Android " + android.os.Build.VERSION.RELEASE + "," + network + " version:" + buildVersionInfo();
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 49 with NetworkInfo

use of android.net.NetworkInfo in project xabber-android by redsolution.

the class NetworkManager method onNetworkChange.

public void onNetworkChange(NetworkInfo networkInfo) {
    NetworkInfo active = connectivityManager.getActiveNetworkInfo();
    LogManager.i(this, "Network: " + networkInfo + ", active: " + active);
    Integer type;
    boolean suspended;
    if (active == null && this.type != null && this.type == networkInfo.getType()) {
        type = getType(networkInfo);
        suspended = isSuspended(networkInfo);
    } else {
        type = getType(active);
        suspended = isSuspended(active);
    }
    if (this.type == type) {
        if (this.suspended == suspended)
            LogManager.i(this, "State does not changed.");
        else if (suspended)
            onSuspend();
        else
            onResume();
    } else {
        if (suspended) {
            type = null;
            suspended = false;
        }
        if (type == null)
            onUnavailable();
        else
            onAvailable(type);
    }
    this.type = type;
    this.suspended = suspended;
}
Also used : NetworkInfo(android.net.NetworkInfo)

Example 50 with NetworkInfo

use of android.net.NetworkInfo in project android by cSploit.

the class Network method isWifiConnected.

public static boolean isWifiConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return info != null && info.isConnected() && info.isAvailable();
}
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