首页 > 解决方案 > Android - 当应用程序在 Google Playstore 中自动更新时如何在应用程序中获取回调

问题描述

每次更新应用程序时,我都需要清除缓存并注销用户,以便用户从后端获取最新数据。我已经实现了支持应用内更新,但由于一些 Playstore 缓存,它不适用于每个用户。我尝试使用以下代码注册我的广播接收器:

<receiver android:name=".YourReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_INSTALL" />
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <data android:scheme="package"/>
    </intent-filter>
</receiver>

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
intentFilter.addDataScheme("package");
registerReceiver(br, intentFilter);

但它没有工作,它没有捕获应用程序更新事件或删除事件。

在以下情况下,当我的应用程序从 Playstore 自动更新时,如何捕获应用程序更新事件?

  1. 应用自动更新时用户没有打开应用
  2. 当应用程序自动更新时,用户已打开应用程序

标签: androidapp-update

解决方案


推荐阅读