android - android.intent.action.DOWNLOAD_COMPLETE 是显式广播吗?

标签 android broadcastreceiver android-manifest android-8.0-oreo android-download-manager

我的应用程序 (targetSdk=25) 在 list 中定义了一个广播接收器,如下所示:

<receiver android:name="my.package.DownloadManagerReceiver"
     android:exported="true">
     <intent-filter>
          <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
     </intent-filter>
</receiver>

每当 Android 的 DownloadManager 时,我的 DownloadManagerReceiver 都会收到通知完成文件下载,因此我可以对下载的文件进行一些处理。

我正在努力将我应用的 targetSdk 迁移到 27 (Oreo)。根据https://developer.android.com/about/versions/oreo/background#broadcasts , 通过 list 注册的隐式广播接收器不应该在 Android O 中工作(那些 whitelisted exceptions 除外)。

但是,当我使用运行 Android 8.0 和 targetSdk=27 的模拟器运行我的应用程序时,我在 list 中定义的广播接收器在下载完成后仍会收到 DownloadManager 的通知

我试图找到 DownloadManager 发送广播的源代码以了解它如何发送广播,但找不到。

有谁知道 android.intent.action.DOWNLOAD_COMPLETE 是显式广播还是隐式广播?知道为什么我的接收器仍在接收该广播吗?

最佳答案

以下是我在深入研究该平台的源代码后发现的内容:

1) 当我们实例化 DownloadManager 时,它保留对应用程序上下文的引用并从该上下文中提取应用程序的包名称

2) 当请求下载时,该包名称被插入到下载数据库的 Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE 列中

3) 下载完成后,DownloadInfo.sendIntentIfRequested()方法将调用 Intent.setPackage()传递包名。根据description of method Intent.setPackage() :

(Usually optional) Set an explicit application package name that limits the components this Intent will resolve to. If left to the default value of null, all components in all applications will considered. If non-null, the Intent can only match the components in the given application package.

根据该描述,我的理解是广播 Intent 将针对我的应用,因此作为显式 Intent 工作。

关于android - android.intent.action.DOWNLOAD_COMPLETE 是显式广播吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51674327/

相关文章:

android - 即使在 list 中添加权限后仍显示 `Missing permission`

java - Android Retrofit with Rx 获取其他 http 代码

android - 使用动画师对其某些属性进行动画处理后,如何将 View 重置为原始状态?

Android:在特定电池电量下启动服务

android - 手机重启后如何记住未决的 Intent 和警报?

java - ContentResolver.requestSync 不调用 SyncAdapter

java - Android spinner Data Binding 使用 XML 并显示选定的值

android TagHandler 和 CSS

Android:如何知道设备何时锁定和解锁

java - Activity 的 Intent 过滤器必须包含 android.intent.action.MAIN 操作