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);
}
}
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();
}
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();
}
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;
}
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;
}
Aggregations