开发者

Horizontal ProgressBar increment with percentage

开发者 https://www.devze.com 2023-04-12 12:19 出处:网络
I have written program in android for downloading from web server I have Used JSON and Http request the program workingproperly... I want to show progress Bar with percentage depending upon things to

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));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号