gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:52:56 25 4
gpt4 key购买 nike

我的应用程序 (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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com