如何在Android Oreo上注册ACTION_PACKAGE_ADDED和ACTION_PACKAGE_REMOVED? [英] How to register for ACTION_PACKAGE_ADDED and ACTION_PACKAGE_REMOVED on Android Oreo?

查看:376
本文介绍了如何在Android Oreo上注册ACTION_PACKAGE_ADDED和ACTION_PACKAGE_REMOVED?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看最新的Android Oreo发行说明,看来这些应用只能注册少数隐式广播. ACTION_PACKAGE_ADDED和ACTION_PACKAGE_REMOVED不在其中.是否有解决这些广播的方法?

Looking at the latest Android Oreo release notes, it seems like only a handful of implicit broadcasts can be registered by the apps. ACTION_PACKAGE_ADDED and ACTION_PACKAGE_REMOVED is not among them. Is there a workaround for receiving these broadcasts?

推荐答案

来自文档:

面向Android 8.0或更高版本的应用无法再在其清单中为隐式广播注册广播接收器.隐式广播是不专门针对该应用的广播.例如,ACTION_PACKAGE_REPLACED是隐式广播,因为它已发送给所有注册的侦听器,让他们知道设备上的某些程序包已被替换.

Apps that target Android 8.0 or higher can no longer register broadcast receivers for implicit broadcasts in their manifest. An implicit broadcast is a broadcast that does not target that app specifically. For example, ACTION_PACKAGE_REPLACED is an implicit broadcast, since it is sent to all registered listeners, letting them know that some package on the device was replaced.

这表示您无法在清单中注册这些意图.您仍可以通过编程方式注册它们,以在应用运行时接收它们.

This says that you cannot register these intents in your manifest. You can still register them programmatically to receive them when your app is running.

您还可以尝试ACTION_PACKAGE_FULLY_REMOVED,这是例外之一您仍然可以通过在清单中注册它来收听.添加包时没有这样的替代".

You might also try ACTION_PACKAGE_FULLY_REMOVED, which is one of the exceptions that you can still listen to by registering it in the manifest. There is no such 'alternative' for when a package is added.

正如CW所指出的,您还可以定期检查已安装应用程序名册中的更改.

As CW noted, you could also periodically check for changes in the roster of installed apps.

您还可以使用轮询,设置JobScheduler作业以经常检查,并通过 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆