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 BroadcastReceiver is a dormant component of android that listens to system-wide broadcast events or intents. When any of these events occur it brings the application into action by either creating a status bar notification or performing a task.
A Service receives intents that were sent specifically to your application, just like an Activity. A Broadcast Receiver receives intents that were broadcast system-wide to all apps installed on the device.
A broadcast receiver will always get notified of a broadcast, regardless of the status of your application. It doesn't matter if your application is currently running, in the background or not running at all.
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:
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
And onReceive method from your BroadcastReceiver should be:
@Override
public void onReceive(Context context, Intent intent) {
Uri data = intent.getData();
if (data.toString().equals("package:" + "com.target.package") {
// action to do
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With