Code example for ConnectivityManager: Querying Network Reachability

Methods: getActiveNetworkInfo

    public void onReceive(Context context, Intent intent) {
        ConnectivityManager cm = (ConnectivityManager) context
        // 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,
            ComponentName locationReceiver = new ComponentName(context,
            ComponentName passiveLocationReceiver = new ComponentName(context,
            // The default state for this Receiver is disabled. it is only 
            // enabled when a Service disables updates pending connectivity. 
Connect your IDE to all the code out there  Get Codota for Java