Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 829
Dhruv Kaushal Avatar asked Aug 04 '26 11:08

Dhruv Kaushal


1 Answers

You could also check the EXTRA_REPLACING extra on the intent (if it is a PACKAGE_REMOVED intent).

public static final String EXTRA_REPLACING

Used as a boolean extra field in ACTION_PACKAGE_REMOVED intents to indicate that this is a replacement of the package, so this broadcast will immediately be followed by an add broadcast for a different version of the same package.

like image 129
nate Avatar answered Aug 06 '26 03:08

nate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!