Horizontal ProgressBar increment with percentage
I have written program in android for downloading from web server I have Used JSON and Http request the program working properly... I want to show progress Bar with percentage depending upon things to be downloading. My query is how to increment the progress bar in percentage depending upon things to be downloaded and pending.开发者_如何学C I know how to calculate percentage but How would I know how much downloading is pending from server.
How much downloading is pending from server.
You have to implement a Range request in your application.
You may use this as a reference especially if you are using chunks. Otherwise, for all simple downloads
URLConnection cxn = url.openConnection();
cxn.connect();
int lenghtBytes = cxn.getContentLength();
how to increment the progress bar
use publishProgress() in case of an AsyncTask
publishProgress((int)(bytesDownloaded * 100 / lenghtBytes));
精彩评论