Android Demo, androiddemo, which can be downloaded and canceled in the background notification bar
The implementation result is as follows:
Because it is a notification bar, how do I transmit it after clicking it? Define a broadcast. Send the broadcast when you click it and register the broadcast.
Cancel the download after receiving 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); // here the user interface is manually canceled, so it will go through the onDestroy () of the activity; Method // cancel the notification to mNotificationManager. cancel (policy_id); binder. cancel (); binder. cancelNotification (); if (binder! = Null & binder. isCanceled () {stopSelf ();} callback. OnBackResult ("cancel ");}}};
Demo: click here