stopping download when internet is not working?
<p>I have been trying to fix this for days now, but to no avail. Essentially, what I'm doing is this:</p>

<ul>
<li>starting a Service for every file name in an Array</li>
<li>services are put in a queue and they are processed one at a time
      - each service downloads a file from a server  &lt; == problem is here</li>
</ul>

<p>When I'm downloading a file sometimes the internet on the mobile phone, especially the WIFI one it doesnt respond in that pages don't load and the download stops or gets stuck at lets say 25%. Now I want to find out when this happens so that I can stop the Service and have been trying to do this for days now but nothing works. This is what I have so far:</p>

<pre><code> URL url = new URL(full_url);
 HttpURLConnection conexion = (HttpURLConnection)url.openConnection();
 //conexion.setConnectTimeout(10000);
 conexion.connect();


    while ((count = input.read(data)) &gt; 0 &amp;&amp; lenghtOfFile &gt; 0){
               total += count;
               downloadProgress = (int)((total*100)/lenghtOfFile);
               Log.e("downloadProgress","" + downloadProgress);
               output.write(data, 0, count);

    } 
</code></pre>

<p>This is what I usually get when the files are being downloaded:
File 1:
download Progress: 1 1 1 1 1 1 1  2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8  9 9 9 9 9 9 9 10 10 10 10 10 10 10 ... 100</p>

<p>and then File 2 something similar:
download Progress: 1 1 1 1 1 1 1  2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8  9 9 9 9 9 9 9 10 10 10 10 10 10 10 ... 100</p>

<p>and let's say on File 3 the internet will go down (not disconnected just pages won't load)
and I get something like this:
File 3:
1 1 1 1 1 1 2 2 2 2 3 3 3 3 3  4 4 4 4 4 4  5  5 5 5 5 5 5  6 6 6 6 6 6  7 7 7 7 7 7 
 8 8 8 8 8 8 9 9 9 9 9 9 9 (internet goes down, gets stuck at 9) </p>

<p>How do I add a method that checks when this happens so that I can stop the Service!</p>

<p>I really need urgent help on this, thanks for your time!</p>

<p><strong>EDIT</strong>:
This the LOG that I get when Internet gets stuck while downloading a file. The download as you can see has gone to 29% and then the internet connection becomes unresponsive in some way in which it doesn't throw any Exception it just stay like that!</p>

<pre><code>11-16 16:18:39.769: ERROR/totaltotal(24691): 29
11-16 16:18:39.859: ERROR/totaltotal(24691): 29
11-16 16:18:39.869: ERROR/totaltotal(24691): 29
11-16 16:18:39.869: ERROR/totaltotal(24691): 29
11-16 16:18:39.879: ERROR/totaltotal(24691): 29
11-16 16:19:04.119: DEBUG/ConnectivityService(162): reportNetworkCondition(1, 0)
11-16 16:19:04.119: DEBUG/ConnectivityService(162): Inet connectivity change, net=1, condition=0,mActiveDefaultNetwork=1
11-16 16:19:04.119: DEBUG/ConnectivityService(162): starting a change hold
11-16 16:19:05.940: DEBUG/BatteryService(162): update start
11-16 16:19:05.940: DEBUG/BatteryService(162): update start
11-16 16:19:05.950: DEBUG/BatteryService(162): update start
11-16 16:19:07.129: DEBUG/ConnectivityService(162): Inet hold end, net=1, condition =0, published condition =0
11-16 16:19:07.129: DEBUG/ConnectivityService(162): no change in condition - aborting
11-16 16:19:15.959: DEBUG/BatteryService(162): update start
11-16 16:19:15.959: DEBUG/BatteryService(162): update start
11-16 16:19:15.969: DEBUG/BatteryService(162): update start
11-16 16:19:25.979: DEBUG/BatteryService(162): update start
11-16 16:19:25.979: DEBUG/BatteryService(162): update start
11-16 16:19:25.989: DEBUG/BatteryService(162): update start
</code></pre>
