android - 在包更新时防止 android.intent.action.PACKAGE_REMOVED

标签 android broadcastreceiver manifest

我在 Manifest 中注册了一个全局的 Broadcast Receiver,它会在用户卸载包时显示一个通知。

 <receiver android:name=".YourReceiver">
        <intent-filter android:priority="999">
            <action android:name="android.intent.action.PACKAGE_REMOVED" />
            <action android:name="android.intent.action.PACKAGE_INSTALL" />
            <action android:name="android.intent.action.PACKAGE_REPLACED"/>
            <action android:name="android.intent.action.PACKAGE_ADDED" />
            <action android:name="com.times.REFRESH_INSTALL_FLAG" />

            <data android:scheme="package" />
        </intent-filter>
    </receiver>

问题是当某些包从 Play Store 更新时 android.intent.action.PACKAGE_REMOVEDandroid.intent.action.PACKAGE_ADDED 相继调用。

问题是我无法区分软件包是卸载还是更新。

一种方法是等到我们收到相同包名的PACKAGE_ADDED,然后关闭通知。

还有其他正确的方法可以实现吗?

最佳答案

我自己搞定了!通过查看收到的包名是否安装来区分!

关于android - 在包更新时防止 android.intent.action.PACKAGE_REMOVED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41972981/

相关文章:

android - 如何使工具栏透明并向后放置图像?

android - Theme.Sherlock.Light.DarkActionBar 中的隐形 ActionMode 项目图标

android - ReceiverRestrictedContext 无法转换为 android.app.Activity

android - 仅当您显式调用 finish() 时才会调用 onDestroy 吗?或者有什么异常(exception)吗?

android - 简单的一个 : does ACTION_DISCOVERY_FINISHED return something like a "no devices found"?

django - 如何在通过 pip 安装的应用程序中包含 django 模板?

android - GPS 不工作

ruby-on-rails - 如何从模块中获取 puppet list 中的文件

maven-2 - 如何从 Maven 程序集插件的 list 中添加任意信息

java - 如何在java的静态方法中使用this关键字?