Code example for ConnectivityManager: Querying Network Reachability

Methods: getActiveNetworkInfo

0
	static final String TAG = "YaximBroadcastReceiver";
	private static int networkType = -1;
	 
	public static void initNetworkStatus(Context context) {
		ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
		networkType = -1;
		if (networkInfo != null) {
			Log.d(TAG, "Init: ACTIVE NetworkInfo: "+networkInfo.toString());
			if (networkInfo.isConnected()) {
				networkType = networkInfo.getType();
			} 
		} 
	} 
 
	@Override 
	public void onReceive(Context context, Intent intent) {
		Log.d(TAG, "onReceive "+intent.getAction());
 
		if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {
			Log.d(TAG, "stop service");