Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check internet connection throughout my application

I'm working on Internet based app,so i need to monitor Internet Connection. link

I used this code in on create of mainActivity to check my internet connection it works fine.

public boolean isOnline() 
{  
ConnectivityManager cm = (ConnectivityManager) 
getSystemService(Context.CONNECTIVITY_SERVICE);  return 
cm.getActiveNetworkInfo().isConnectedOrConnecting();
}

But i need this monitoring should be done through out application. Where should i use this ? Any AsyncTask needed?

like image 256
shanmugamgsn Avatar asked Dec 28 '22 11:12

shanmugamgsn


1 Answers

create a BroadcastReceiver to detect change in connection status. see Eric's answer here

like image 154
josephus Avatar answered Jan 09 '23 09:01

josephus