title: Downloading an mp3 file from url
body: <p>I am trying to create an app that can download music files.</p>
  
  <p>How to download mp3 file in android from a URL and save it in SD card??</p>
  
  <p>I use this code but <code>lenghtOfFile</code> always <code>&lt;=350</code>:</p>
  
  <pre><code> String fileUrl = (String) params[0];
                  path = (String) params[1];
                  InputStream input = null;
                  OutputStream output = null;
                  HttpURLConnection connection = null;
                  int count;
                  try {
                      URL url = new URL(fileUrl);
                      URLConnection connection = url.openConnection();
                      connection .connect();
                      // this will be useful so that you can show a tipical 0-100% progress bar
                      int lenghtOfFile = connection .getContentLength();
  
                      // downlod the file
                      input = new BufferedInputStream(url.openStream());
                      output = new FileOutputStream(path);
  
                      byte data[] = new byte[1024];
  
                      long total = 0;
  
                      while ((count = input.read(data)) != -1) {
                          total += count;
                          // publishing the progress....
                          publishProgress((int)(total*100/lenghtOfFile));
                          output.write(data, 0, count);
                      }
  
                      output.flush();
                      output.close();
                      input.close();
  </code></pre>
  
  <p>url files :</p>
  
  <pre><code>http://snd1.tebyan.net/1391/12/08_Khaneh_D_117323.mp3
  http://snd1.tebyan.net/1393/12/100_Pedar_Va_Madar_D_148797.mp3
  and .....
  </code></pre>
  
  <p><strong>update :</strong></p>
  
  <pre><code>int code= connection.getResponseCode();\\302
  String _result= connection.getResponseMessage();\\ found
  </code></pre>
  
  <p><strong>note :</strong></p>
  
  <p>Files do download in <code>Samsung Galaxy S3</code>, but files do not download in <code>Samsung tablet N8000</code> </p>