是否可以监听Manifest.xml中的DownloadManager.ACTION_DOWNLOAD_COMPLETE
?
我发现的所有示例都使用 registerReceiver(downloadCompleteReceiver,new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
来自 class
但我想在 Manifest.xml 中接收它这样我就可以在应用程序关闭时收听。
当我尝试在 Manifest.xml 中为接收器设置 Intent 过滤器时,我找不到此操作
最佳答案
Beginning with Android 8.0 (API level 26), the system imposes additional restrictions on manifest-declared receivers.
If your app targets Android 8.0 or higher, you cannot use the manifest to declare a receiver for most implicit broadcasts (broadcasts that don't target your app specifically). You can still use a context-registered receiver when the user is actively using your app.
来自Is android.intent.action.DOWNLOAD_COMPLETE an explicit broadcast?我们了解到android.intent.action.DOWNLOAD_COMPLETE
似乎是显式广播,因此定义 <receiver>
应该没有问题即使它不是自动完成的,也可以在 list 中找到它。因此只需使用 android.intent.action.DOWNLOAD_COMPLETE
操作添加它即可.
<receiver
android:name=".your.DownloadCompleteReceiver"
android:permission="android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
</intent-filter>
</receiver>
关于android - list 中 DownloadManager.ACTION_DOWNLOAD_COMPLETE 的接收器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57560802/