satellitemundo
Newbie
Hi Friends,
I want to download a file from server and while downloading I want to show progress bar to display downloading pogress. I thought this is pretty much simple. But I am facing strange problem. Progress bar's setProgress method do not show the updated view of progress.
Below is my xml file
Below is my java code...
ANd on click of a button I am starting the downloading...
It download's the file. But do not update the progress. Please Help...
I want to download a file from server and while downloading I want to show progress bar to display downloading pogress. I thought this is pretty much simple. But I am facing strange problem. Progress bar's setProgress method do not show the updated view of progress.
Below is my xml file
Code:
<ProgressBar android:id="@+id/downloading_progress_bar"
android:visibility="invisible"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="5dip"
android:layout_marginTop="2dip"/>
Code:
downloading_progress_bar=(ProgressBar)findViewById(R.id.downloading_progress_bar);
ANd on click of a button I am starting the downloading...
Code:
else if(v==priceImage)
{
if(priceImage.getText().toString().equalsIgnoreCase("free"))
{
downloading_progress_bar.setVisibility(View.VISIBLE);
downloading_progress_bar.setProgress(0);
downloading_progress_bar.setMax(100);
String downloadURL="http://watkinsbooks.cfmdeveloper.com/Books/eb_3/20_634436335548872500.epub";
try
{
int count;
URL url= new URL(downloadURL);
URLConnection conexion = url.openConnection();
conexion.connect();
int lengthOfFile=conexion.getContentLength();
InputStream input=new BufferedInputStream(url.openStream());
OutputStream output=new FileOutputStream("/sdcard/sample_epub.epub");
byte[] data =new byte[1024];
long total=0;
while((count=input.read(data))!=-1)
{
//Log.v("","Reading file...");
Log.v(TAG,"-----------------------------------------");
total+=count;
Log.v(TAG,"Count = "+count);
Log.v(TAG,"Total = "+total);
int progress=(int)(total*100/lengthOfFile);
Log.v(TAG,"Progress "+(int)(total*100/lengthOfFile));
if(progress%10==0)
{
if(downloading_progress_bar.getProgress()!=progress)
{
downloading_progress_bar.setProgress((int)(total*100/lengthOfFile));
}
}
output.write(data,0,count);
}
output.flush();
output.close();
input.close();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
It download's the file. But do not update the progress. Please Help...