In a BroadcastReceiever I am using this code to detect when the device is connected to the internet (when a connection is available - WiFi/data):
if(arg1.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
ConnectivityManager connMgr = (ConnectivityManager) arg0.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if(networkInfo != null && networkInfo.isConnected() && networkInfo.isAvailable()) {
Toast.makeText(Context, "Connected to internet", Toast.LENGTH_LONG).show();
}
The problem:
Phone is disconnected
I enable WiFi or data to connect
I receive the notification but too many times. The phone is still connected but I keep receiving notifications.
Why?
Thanks