protected String doInBackground(String... f_url) { int count; try { String root = Environment.getExternalStorageDirectory().toString(); System.out.println("Downloading"); URL url = new URL(f_url[0]); URLConnection conection = url.openConnection(); conection.connect(); int lenghtOfFile = conection.getContentLength(); InputStream input = new BufferedInputStream(url.openStream(), 8192); OutputStream output = new FileOutputStream(root+"/"+list.get(con_position)+".mp3"); byte data[] = new byte[1024]; long total = 0; while ((count = input.read(data)) != -1) { total += count; output.write(data, 0, count); } output.flush(); output.close(); input.close(); } catch (Exception e) { Log.e("Error: ", e.getMessage()); } return null; } @Override protected void onPostExecute(String file_url) { System.out.println("Downloaded"); pDialog.dismiss(); } }
with the manifest everything is in order, in the doInBackground I pass the URL string to the resource. It seems the traffic goes but not for long, therefore there are no files, please help