this is my inner class that handles the downloading and progressbar
public class DownloadDBTask extends AsyncTask<Object, Integer, Object>
{
private int mProgress;
public Object doInBackground(Object ...urls)
{
//download file
int totalSize =0;
try
{
URL urlFile = new URL("http://www.xxx.com/test.db");
URLConnection conn;
conn = urlFile.openConnection();
totalSize = conn.getContentLength();
Log.i("INFO","total size of file "+totalSize);
BufferedInputStream bis = new
BufferedInputStream(urlFile.openStream());
BufferedOutputStream bout = new BufferedOutputStream(new
FileOutputStream(PATH+DB_NAME),1024);
byte data[] = new byte[1024];
int bufferSize =0;
int currentSize = 0;
while((bufferSize = bis.read(data)) != -1 )
{
currentSize +=bufferSize;
bout.write(data,0,bufferSize);
publishProgress((int) ((currentSize / (float) totalSize) * 100));
}
Log.i("INFO","Done downloading");
bout.flush();
bis.close();
bout.close();
}
catch(IOException e)
{
Log.e("ERROR",e.toString());
}
return (new Object());
}
public void onPostExecute(Object result) {
mProgressDialog.dismiss();
}
protected void onProgressUpdate(Integer... progress) {
mProgressDialog.setProgress(progress[0]);
}
protected void onPreExecute(){
showDialog(2);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe from this group, send email to
android-developers+unsubscribegooglegroups.com or reply to this email with the
words "REMOVE ME" as the subject.