Search in sources :

Example 91 with ConnectivityManager

use of android.net.ConnectivityManager in project Android by Tracman-org.

the class ConnectionReceiver method onReceive.

//private static final String TAG = "ConnectionReceiver";
@Override
public void onReceive(Context context, Intent intent) {
    //Log.d(TAG,"onReceive() called");
    // Get connection information
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    // Prepare intent
    Intent locationServiceIntent = new Intent(context, LocationService.class);
    // Check connection
    if (networkInfo != null) {
        //Log.d(TAG, "Connected");
        context.startService(locationServiceIntent);
    } else {
        //Log.d(TAG,"Disconnected");
        context.stopService(locationServiceIntent);
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) Intent(android.content.Intent)

Example 92 with ConnectivityManager

use of android.net.ConnectivityManager in project Weather by Sparker0i.

the class CheckConnection method isNetworkAvailable.

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

Example 93 with ConnectivityManager

use of android.net.ConnectivityManager in project wh-app-android by WhiteHouse.

the class NetworkUtils method checkNetworkAvailable.

public static boolean checkNetworkAvailable(Context ctx) {
    ConnectivityManager cm = ((ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE));
    NetworkInfo info = cm.getActiveNetworkInfo();
    return info != null && info.isConnected();
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 94 with ConnectivityManager

use of android.net.ConnectivityManager in project Atom_Android by Rogrand-Dev.

the class NetUtils method isMobileNetworkConnected.

/**
     * 检查手机网络(4G/3G/2G)是否连接
     */
public static boolean isMobileNetworkConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mobileNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    return mobileNetworkInfo != null;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 95 with ConnectivityManager

use of android.net.ConnectivityManager in project LshUtils by SenhLinsh.

the class NetWorkUtils method getNetworkTypeName.

/** 获取网络类型名称 */
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)

Aggregations

ConnectivityManager (android.net.ConnectivityManager)379 NetworkInfo (android.net.NetworkInfo)275 Context (android.content.Context)14 TelephonyManager (android.telephony.TelephonyManager)14 Intent (android.content.Intent)11 RemoteException (android.os.RemoteException)11 Test (org.junit.Test)11 WifiManager (android.net.wifi.WifiManager)9 Method (java.lang.reflect.Method)9 Network (android.net.Network)8 IOException (java.io.IOException)8 PackageManager (android.content.pm.PackageManager)7 UserManager (android.os.UserManager)7 SharedPreferences (android.content.SharedPreferences)6 NetworkCapabilities (android.net.NetworkCapabilities)6 Activity (android.app.Activity)5 ApplicationInfo (android.content.pm.ApplicationInfo)5 IPackageManager (android.content.pm.IPackageManager)5 PackageInfo (android.content.pm.PackageInfo)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5