Android implementation background notification bar download and can cancel the demo

Source: Internet
Author: User

The implementation results are as follows:

Because it is the notification bar, then how to pass after the click? Define a broadcast, send this broadcast when clicked, register this broadcast.

Cancel the download when you receive the broadcast. The key code is here.

Broadcastreceiver Onclickcancellistener = new Broadcastreceiver () {@Overridepublic void OnReceive (context context, Intent Intent) {if (Intent.getaction (). Equals (action_cancel_download_apk)) {//todo;;/ /App.setdownload (false);//This is the user interface manual cancellation, so will go through the activity of the OnDestroy ();//Cancel Notification mnotificationmanager.cancel (NOTIFY_ID) ; Binder.cancel (); binder.cancelnotification (); if (binder! = null && binder.iscanceled ()) {stopself ()} Callback. Onbackresult ("Cancel");}};

Demo: Punch here

Android implementation background notification bar download and can cancel the demo

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.