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?
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With