相关疑难解决方法(0)

Android N - 下载管理器通知取消按钮

Android N 在下载管理器通知中有一个新的取消按钮。

我想在我的应用程序中执行一些代码,以在用户按下此按钮时停止进度条。如果有的话,调用哪个方法?

另请注意,意图过滤器操作 DownloadManager.ACTION_NOTIFICATION_CLICKED 仅在用户单击通知本身时触发,而不是在他/她单击“取消”按钮时触发。

 if_downloadManager = new IntentFilter();
    if_downloadManager.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
    if_downloadManager.addAction(DownloadManager.ACTION_NOTIFICATION_CLICKED);

    br_downloadManager = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                ....
            }

            if (DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action)) {
                // This code is not executed when the user presses the Cancel Button in the Download Manager Notification
            }       
        }
    };
Run Code Online (Sandbox Code Playgroud)

提前致谢。

android cancel-button android-notifications android-download-manager

5
推荐指数
1
解决办法
3772
查看次数