Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I monitor the network connection status in Android?

I have a Service that is downloading a file from a server. I warn the user to only download the file over Wireless LAN before the download starts.

My problem is that my download gets stuck if I loose the network connection. Is there a way to listen for changes in network connection or if it is lost entirely?

like image 368
Janusz Avatar asked Jul 22 '10 09:07

Janusz


People also ask

How do I check network connection status?

Select the Start button, then type settings. Select Settings > Network & internet. The status of your network connection will appear at the top. Windows 10 lets you quickly check your network connection status.

How do I view network connections on Android?

If you navigate to Android Settings—>Data usage and tap on any of the apps that's using cellular connection on your device to connect to the internet, you will see two sections against each app. There's the Foreground data usage and Background data usage.


1 Answers

Listen for CONNECTIVITY_ACTION

This looks like good sample code. Here is a snippet:

BroadcastReceiver networkStateReceiver = new BroadcastReceiver() {      @Override     public void onReceive(Context context, Intent intent) {         Log.w("Network Listener", "Network Type Changed");     } };  IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);         registerReceiver(networkStateReceiver, filter); 
like image 127
Pentium10 Avatar answered Sep 30 '22 13:09

Pentium10