I have a problem with Progress Bar showing % of download completed. I have a service class in which the downloading takes place. I can get the start time and end time of download from this class. In Main Activity on clicking a button I have to show the progress %. I heard that its possible through AsyncTask but I have no clue about how it works. Please help me with some sample code example related to this. Thanks
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
try like this
here is a class
class DownloadFileAsync extends AsyncTask {
} }
and here is a xml file
http://pastie.org/4265745
Best of luck Aamirkhan I.
I would prefer AsyncTask for this.
Here's an example
here's the AsyncTask
This can be done using Download from Service as well as Download Manager class. Refer this question for details.
EDIT
The percentage completed is what you actually publish in the progress dialog. If you want to display the percentage, you may use this (total * 100 / fileLength).
Use this code to display the percentage in the desired textview.