Problem in File Downloading from server in android application -


i using code of snippet download mp4 files server. file download properly, sometime downloading process stops downloading automatically. progress bar stop incrementing. there kernel process stop download.

//+++++++++= function call ++++++++++++++++  download_file_name = "demo.mp4"; graburl("mp4 file server url");    //+++++++++++++++++++++++++++++++++++++++++  public void graburl(string url) {              new graburl().execute(url);       } private class graburl extends asynctask<string, void, void> {                     private final httpclient client = new defaulthttpclient();                     private string content;                     private string error = null;                     private progressdialog dialog = new progressdialog(slideshow.this);                      protected void onpreexecute() {                        showdialog(dialog_progress);                mprogressdialog.setprogress(0);                    }              protected void doinbackground(string... url) {                 int count;                try {                   url url2 = new url(url[0]);                   urlconnection conexion = url2.openconnection();                   conexion.setusecaches(true);                   conexion.connect();                    // useful can show tipical 0-100% progress bar                   int lenghtoffile = conexion.getcontentlength();                   mprogressdialog.setmax(lenghtoffile);                   // downlod file                   inputstream input = new bufferedinputstream(url2.openstream());                   outputstream output = new fileoutputstream(download_file_name);                    byte data[] = new byte[1024];                    while ((count = input.read(data)) != -1) {                        mprogressdialog.incrementprogressby(data.length);                           output.write(data, 0, count);                   }                    output.close();                   input.close();               } catch (exception e) {}               return null;           }   

on mobile device internet connection has treated unreliable.

your code shows downloading method no connection management. if internet connection stops reason, code won't able relaunch it.

you can use broadcast receiver connectivitymanager : http://developer.android.com/reference/android/net/connectivitymanager.html notified when connection drops , relaunch download there when connection again.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -