Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid- downloading file sometimes stops randomly
    text
    copied!<p>I currently have an <code>asynctask</code> which downloads an mp3 to a folder on the SDCARD. Most of the time it works fine, but sometimes, the download simply skips to being done and does not fully download the song. Any ideas why this is happening?</p> <p>Code:</p> <pre><code>@Override protected String doInBackground(String... url) { int count; try { URL url2 = new URL(sdrUrl); HttpURLConnection connection = (HttpURLConnection) url2.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.connect(); int lengthOfFile = connection.getContentLength(); //make the stop drop rave folder File sdrFolder = new File(Environment.getExternalStorageDirectory() + "/StopDropRave"); boolean success = false; if(!sdrFolder.exists()){ success = sdrFolder.mkdir(); } if (!success) { String PATH = Environment.getExternalStorageDirectory() + "/StopDropRave/"; file = new File(PATH); file.mkdirs(); } else { String PATH = Environment.getExternalStorageDirectory() + "/StopDropRave/"; file = new File(PATH); file.mkdirs(); } String[] path = url2.getPath().split("/"); String mp3 = path[path.length - 1]; String mp31 = mp3.replace("%20", " "); String sdrMp3 = mp31.replace("%28", "("); String sdrMp31 = sdrMp3.replace("%29", ")"); String sdrMp32 = sdrMp31.replace("%27", "'"); File outputFile = new File(file, sdrMp32); FileOutputStream fos = new FileOutputStream(outputFile); InputStream input = connection.getInputStream(); byte[] data = new byte[1024]; long total = 0; while ((count = input.read(data)) != -1) { total += count; publishProgress(""+(int) (total * 100 / lengthOfFile)); fos.write(data, 0, count); } fos.close(); input.close(); } catch (IOException e) { } return null; } </code></pre> <p>This is what appears in my log car:</p> <pre><code>08-02 19:11:18.834: WARN/System.err(16225): java.net.SocketException: Connection timed out 08-02 19:11:18.843: DEBUG/AK8973(121): HRET = AKSC_HOF_DSS_REQUEST 08-02 19:11:18.853: DEBUG/AK8973(121): HRET = AKSC_HOF_DSS_REQUEST 08-02 19:11:18.873: DEBUG/AK8973(121): HRET = AKSC_HOF_DSS_COMPLETE 08-02 19:11:18.923: WARN/System.err(16225): at org.apache.harmony.luni.platform.OSNetworkSystem.read(Native Method) 08-02 19:11:18.983: WARN/System.err(16225): at dalvik.system.BlockGuard$WrappedNetworkSystem.read(BlockGuard.java:273) 08-02 19:11:18.983: WARN/System.err(16225): at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:458) 08-02 19:11:18.983: WARN/System.err(16225): at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:85) 08-02 19:11:18.983: WARN/System.err(16225): at java.io.BufferedInputStream.read(BufferedInputStream.java:319) 08-02 19:11:18.983: WARN/System.err(16225): at org.apache.harmony.luni.internal.net.www.protocol.http.FixedLengthInputStream.read(FixedLengthInputStream.java:44) 08-02 19:11:18.983: WARN/System.err(16225): at java.io.InputStream.read(InputStream.java:157) 08-02 19:11:18.983: WARN/System.err(16225): at ravebox.dev.sdr.BlogActivity$DownloadFile.doInBackground(BlogActivity.java:308) 08-02 19:11:18.993: WARN/System.err(16225): at ravebox.dev.sdr.BlogActivity$DownloadFile.doInBackground(BlogActivity.java:1) 08-02 19:11:18.993: WARN/System.err(16225): at android.os.AsyncTask$2.call(AsyncTask.java:185) 08-02 19:11:18.993: WARN/System.err(16225): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 08-02 19:11:18.993: WARN/System.err(16225): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 08-02 19:11:18.993: WARN/System.err(16225): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 08-02 19:11:18.993: WARN/System.err(16225): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 08-02 19:11:18.993: WARN/System.err(16225): at java.lang.Thread.run(Thread.java:1019) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload