tags:

views:

23

answers:

1

Hi'

Is there a piece of code I could write to be notified when a download finishes in android, and be able to execute some custom actions on this event ?

+1  A: 

A download of...what?

If you are downloading via your own code (HttpUrlConnection or HttpClient), you know when the download is complete.

If you are using WebView and want to know when the page is loaded, you can use a WebViewClient to be notified of that event.

If the user is using the Browser application or a third-party browser, you cannot "be notified when a download finishes" in general. If you are set up to be a handler of that MIME type, and if the user chooses to open the file in your ACTION_VIEW activity, then you will be "notified" by your activity starting up.

CommonsWare
Sorry I forgot to specify that. I want to be notified when the android browser downloads something.
rantravee
Could you be more specific on that ? .Where should I set up a handler ? , and when will this handler will be called ?
rantravee
If you are trying to create a handler for a particular MIME type, you need to create an activity with an intent-filter that specifies the MIME type and the ACTION_VIEW action. There are examples of this in the Android source code. Your activity will then be an option for the user for opening the downloaded file.
CommonsWare
I got the idea , unfortunately it's not fit for my use
rantravee
You cannot otherwise be notified of Browser downloads -- that would be a privacy violation.
CommonsWare