Android Downloadmanger 2 for download completion and click to download notifications for listening

Source: Internet
Author: User

Listening Download Complete:

To receive a notification after the download is complete, you need to register a receiver to receive the Action_dowload_complete broadcast. It will contain a extra_download_id extra that contains the reference ID for the download that has been completed:

public void Funclick (view view) {String servicestring = Context.download_service;downloadmanager Downloadmanager; Downloadmanager = (Downloadmanager) getsystemservice (servicestring); Uri uri = uri.parse ("http://img00.hc360.com/it/201206/201206121034589404.jpg");D ownloadmanager.request Request = new Request (URI); request.setallowednetworktypes (Request.network_wifi); Downloadmanager.getrecommendedmaxbytesovermobile (Getapplicationcontext ()); final long myreference = Downloadmanager.enqueue (request); Intentfilter filter = new Intentfilter (downloadmanager.action_download_complete); Broadcastreceiver receiver = new Broadcastreceiver () {@Overridepublic void OnReceive (context context, Intent Intent) { Long reference = Intent.getlongextra (downloadmanager.extra_download_id,-1); if (reference = = Myreference) {// Perform some operations on the downloaded file}}};registerreceiver (receiver, filter);}

Monitor Click to download the notification bar:

Intentfilter filter = new Intentfilter (downloadmanager.action_notification_clicked); Broadcastreceiver receiver = new Broadcastreceiver () {@Overridepublic void OnReceive (context context, Intent Intent) { String extraid = downloadmanager.extra_notification_click_download_ids;long[] References = Intent.getlongarrayextra ( Extraid); for (long reference:references) {if (reference = = Myreference) {///For some operations on downloaded files}}}};registerreceiver (receiver , filter);


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.