Search code examples
androidbroadcastreceivermanifest

Prevent android.intent.action.PACKAGE_REMOVED on Package Update


I have registered a global Broadcast Receiver in Manifest which shows a notification when the user uninstalls a package.

 <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>

The problem is that when some package is updating from Play Store the action android.intent.action.PACKAGE_REMOVED and android.intent.action.PACKAGE_ADDED are called one after another.

The problem is that I am unable to differentiate whether a package is uninstalled or updating.

One of the way is to wait till we receive PACKAGE_ADDED for the same package name and then dismiss a notification.

Is there any other correct method to achieve this?


Solution

  • Got it myself! Distinguish by checking whether the received package name is installed or not!