android - list 中 DownloadManager.ACTION_DOWNLOAD_COMPLETE 的接收器

标签 android android-manifest android-download-manager

是否可以监听Manifest.xml中的DownloadManager.ACTION_DOWNLOAD_COMPLETE

我发现的所有示例都使用 registerReceiver(downloadCompleteReceiver,new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); 来自 class 但我想在 Manifest.xml 中接收它这样我就可以在应用程序关闭时收听。 当我尝试在 Manifest.xml 中为接收器设置 Intent 过滤器时,我找不到此操作

最佳答案

作为official documentation状态:

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/

相关文章:

Android:监听 Activity onDestroy()

java - 上传到 Google Play 时出错 : android:label attribute: attribute is not a string value

android - 如何在android中准备数字加密签名?

java - 为什么我的自定义微调器被禁用/无响应?

android:使用Intent.ACTION_BOOT_COMPLETED还是...?

android - 在 AndroidManifest.xml 中声明类

android - Android下载管理器如何修改更新间隔

android - DownloadManager 内部 fragment 错误

android - 如何检查是否启用了 Android 下载管理器?

c# - Unity3d开发: JNI ERROR (app bug): accessed stale local reference 0x200001 (index 0 in a table of size 0)