Code example for ConnectivityManager: Querying Network Reachability

Methods: getActiveNetworkInfo

0
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
 
        // Check if we are connected to an active data network. 
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        boolean isConnected = (activeNetwork != null) && activeNetwork.isConnectedOrConnecting();
 
        if (isConnected) {
            PackageManager pm = context.getPackageManager();
 
            ComponentName connectivityReceiver = new ComponentName(context,
                    IgnitedConnectivityChangedReceiver.class); 
            ComponentName locationReceiver = new ComponentName(context,
                    IgnitedLocationChangedReceiver.class); 
            ComponentName passiveLocationReceiver = new ComponentName(context,
                    IgnitedPassiveLocationChangedReceiver.class); 
 
            // The default state for this Receiver is disabled. it is only 
            // enabled when a Service disables updates pending connectivity. 
            pm.setComponentEnabledSetting(connectivityReceiver,