Download manager android 2.2 example

how to create own download manager in android 2.2

please provide me some sample answer.

Step1 Look for Example on How to Download Files in Android

Step2 Look for Example on How to perform operations in AsyncTask.

Step3 Look for Example on How to Display Download Progress while Downloading.

Step4 Look for Example on How to send Custom Broadcast when Task is completed

Step5 Look for Example on How to Persist AsysncTask operation even on device rotation

Step6 Look for Example on How to Show Download Progress in Notification.


Below is example code.

1. Use AsyncTask and show the download progress in a dialog

The method above (doInBackground) runs always on a background thread. You shouldn’t do any UI tasks there. On the other hand, the onProgressUpdate and onPreExecute run on the UI thread, so there you can change the progress bar:

2. Download from Service

The big question here is: how do I update my activity from a service. In the next example we are going to use two classes you may not be aware of: ResultReceiver and IntentService. ResultReceiver is the one that will allow us to update our thread from a service; IntentService is a subclass of Service which spawns a thread to do background work from there (you should know that a Service runs actually in the same thread of your app; when you extends Service, you must manually spawn new threads to run CPU blocking operations).

Download service can look like this:

Add the service to your manifest:

And the activity will look like this:

// initialize the progress dialog like in the first example

// this is how you fire the downloader

Download manager android 2.2 example

Here is were ResultReceiver comes to play:

download link here