Downloading .mp3 file on Android webview -


i need help.

i have activity:

import android.app.activity; import android.os.bundle; import android.webkit.webview;  public class webviewactivity extends activity {         private webview webview;         public void oncreate(bundle savedinstancestate) {                  super.oncreate(savedinstancestate);                 setcontentview(r.layout.webview);                  webview = (webview) findviewbyid(r.id.webview1);                 webview.getsettings().setjavascriptenabled(true);                 webview.loadurl("file:///android_asset/index.html");         }  } 

how download file, if url = .mp3 ?

better use async task

protected string doinbackground(string... arg0) {             int count;             try {                 system.out.println("file path in dobackground: "+globalvariable.getstrpath());                 url url = new url(globalvariable.getstr());                 httpurlconnection c = (httpurlconnection) url.openconnection();                 c.setrequestmethod("get");                 c.setdooutput(true);                 c.connect();                 int lenghtoffile = c.getcontentlength();                 string path = environment.getexternalstoragedirectory() + "/foldername/";                 log.v("appname", "path: " + path);                 file file = new file(path);                 file.mkdirs();                  file outputfile = new file(file, filename);                  fileoutputstream fos = new fileoutputstream(outputfile);                  inputstream = c.getinputstream();                  byte[] buffer = new byte[1024];                 long total = 0;                 system.out.println("filesize usibng buffer: "+is.read(buffer));                 while ((count = is.read(buffer)) != -1) {                     total += count; //                  publishprogress("" + (long) ((total * 100) / count));                 //  publishprogress("" + (long) ((total) / count));                     publishprogress("" + (long) ((total) / count));                     fos.write(buffer, 0, count);                 }                 fos.close();                 is.close();              } catch (ioexception e) {                 log.d("myappname", "error: " + e);             }             return null;         } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -