So, im working on something that requires me to know when another application on the device is being updated. So my question is quite simple, does lets say YouTube or Spotify send a broadcast when the application is updating, and if so, what do i need to catch with my broadcastReceiver.
Android app update broadcast
13.4k views Asked by user3050720 AtThere are 3 answers
ACTION_PACKAGE_REPLACED is action triggered when an application is being updated According to docs :
A new version of an application package has been installed, replacing an existing version that was previously installed. The data contains the name of the package.
intent.getPackage()
returns the package/application this intent was specifically addressed to but it was sent to any interested receiver, therefore, there isn't such package.
Use intent.getData()
which returns the updated package as an Uri
Add the below intent filter while registering a broadcast receiver in your Manifest.xml
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
According to android docs: Broadcast Action: A new version of your application has been installed over an existing one. This is only sent to the application that was replaced. It does not contain any additional data; to receive it, just use an intent filter for this action.
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
And onReceive method from your BroadcastReceiver should be:
@Override
public void onReceive(Context context, Intent intent) {
// action to do
}
Your intent filter should be like:
And onReceive method from your BroadcastReceiver should be: