Search in sources :

Example 41 with NetworkInfo

use of android.net.NetworkInfo in project superCleanMaster by joyoyao.

the class AppUtil method isMobile.

/**
     * 判断当前网络是否是移动数据网络.
     *
     * @param context the context
     * @return boolean
     */
public static boolean isMobile(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        return true;
    }
    return false;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 42 with NetworkInfo

use of android.net.NetworkInfo in project nmid-headline by miao1007.

the class NetworkUtils method isNetworkAvailable.

public boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 43 with NetworkInfo

use of android.net.NetworkInfo in project packer-ng-plugin by mcxiaoke.

the class MainActivity method addNetworkInfoSection.

private void addNetworkInfoSection() {
    StringBuilder builder = new StringBuilder();
    builder.append("[Network]\n");
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info != null) {
        builder.append(info);
    }
    builder.append("\n\n");
    addSection(builder.toString());
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 44 with NetworkInfo

use of android.net.NetworkInfo in project Android-Boilerplate by hitherejoe.

the class NetworkUtil method isNetworkConnected.

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

Example 45 with NetworkInfo

use of android.net.NetworkInfo in project Android by hmkcode.

the class MainActivity method isConnected.

public boolean isConnected() {
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected())
        return true;
    else
        return false;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

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