Tag: android download manager

Android的奥利奥(API26)和android.app.DownloadManager

乡亲! 此代码不适用于Android奥利奥(但在旧版本上可以,我可以看到通知和DownloadManager.ACTION_DOWNLOAD_COMPLETE广播消息)。 科特林 testButton.setOnClickListener { val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager val uri = Uri.parse(“[url for a mp3 file]”) val request = DownloadManager.Request(uri) request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI) request.setAllowedOverRoaming(false) request.setTitle(“Test mp3”) request.setDescription(“Wow!”) request.setVisibleInDownloadsUi(true) request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE) request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, “/GadgetSaint/” + “/” + “Sample” + “.mp3”) val reference = downloadManager.enqueue(request) }

如何在android中以编程方式捕获取消下载事件

当文件开始下载时,我正在显示进度条,如果它已完成,我更改了成功下载图标的进度栏。 它完美的作品,但我面临的问题是,如果有人点击通知托盘中的取消按钮,它不会发送广播,我已经创建接收广播,如果文件被下载。 我正在使用DownloadManager下载文件,而且我们知道在棉花糖,我们得到一个选项来下载文件,但我怎样才能捕获这个取消按钮的事件。 这是我的代码: <receiver android:name=".adapters.VideoListAdapter$VideoDownloadedReceiver"> <intent-filter> <action android:name="android.intent.action.DOWNLOAD_COMPLETE" /> <action android:name="android.intent.action.DOWNLOAD_CANCEL" /> </intent-filter> </receiver> public static class VideoDownloadedReceiver extends BroadcastReceiver implements AsyncResponse { @Override public void onReceive(Context context, Intent intent) { //perform event //works well if files gets completed but not if download gets cancel } }