I am developing an android broadcast receiver for checking internet connection.
The problem is that my broadcast receiver is being called two times. I want it to get
Answer to your first question: Your broadcast receiver is being called two times because
You have added two
Change in network connection :
Change in WiFi state:
Just use one:
.
It will respond to only one action instead of two. See here for more information.
Answer to your second question (you want receiver to call only one time if internet connection available):
Your code is perfect; you notify only when internet is available.
UPDATE
You can use this method to check your connectivity if you want just to check whether mobile is connected with the internet or not.
public boolean isOnline(Context context) {
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());
}