Android Downloading File with Circular Progress bar

When our application does a task that takes a considerable amount of time, it is common sense to show the progress of the task to the user.
In this tutorial I will be discussing the implementation of a progress bar.

As an example, I am displaying a progress bar that runs while the app downloads an image from the web. Once the image is downloaded completely I am showing the image in a image view and saving to SD Card.
You could modify this example and try it with any file type you may wish.

1. In layout, I declare 2 progress bars (a normal progress bar and a circular progress bar) to making comparison.
activity_download.xml: 2. Declaring res/drawable/style_circular.xml to custom progress bar layout: 3. In DownloadActiviy, in order to download a file from Internet, I use an AsyncTask, saving file and showing to and ImageView after it finish:
4. Adding some necessary methods, we have full code:
5. Open AndroidManifest.xml file and add internet connect permission and writing to sdcard permission:


<!-- Permission: Allow Connect to Internet -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Permission: Writing to SDCard -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

6. Some result screens (click for full size):
pic name pic name pic name

Share


Previous post
« Prev Post
Next post
Next Post »