Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

broadcast receiver for no interner android studio

package com.keshav.networkchangereceiverexample.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

import static com.keshav.networkchangereceiverexample.MainActivity.dialog;

public class NetworkChangeReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        try
        {
            if (isOnline(context)) {
                dialog(true);
                Log.e("keshav", "Online Connect Intenet ");
            } else {
                dialog(false);
                Log.e("keshav", "Conectivity Failure !!! ");
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }

    private boolean isOnline(Context context) {
        try {
            ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo netInfo = cm.getActiveNetworkInfo();
            //should check null because in airplane mode it will be null
            return (netInfo != null && netInfo.isConnected());
        } catch (NullPointerException e) {
            e.printStackTrace();
            return false;
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: @restcontroller 
Java :: spring boot send api request 
Java :: get selected item spinner 
Java :: java for loop syntax 
Java :: fill array with random numbers 
Java :: easter egg 
Java :: meaning of instantiated in java 
Java :: java tree traversal 
Java :: java return pair 
Java :: convert string array to string 
Java :: encryption 
Java :: is it possible to declare two conditions in for loop in javascrip 
Java :: java constructor example 
Java :: list of list in java 
Java :: advantages of using java 
Java :: android studio tabbed activity 
Java :: wrapper classes in java ebhor.com 
Java :: how to use a while statement with char in java 
Java :: labeled statement in java ex 
Java :: if else bedingungen java 
Java :: Algorithms - sum 
Java :: pvector maximum dimension 
Java :: how to extract word from string in java 
Java :: Java program to print Student Info by using Class, Object, Method. 
Java :: okhttp Updating Views on UIThread 
Java :: Picked up _JAVA_OPTIONS: -Xmx256M intillij 
Java :: unique numbers in array java 
Java :: tinyint in java 
Java :: int[] left = Arrays.copyOfRange(arr, l, m + 1); 
Java :: Sauvegarder une partie en cours dans un fichier texte java 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =