Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app update broadcast

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.

like image 800
user3050720 Avatar asked Jun 09 '15 09:06

user3050720


People also ask

What is Android broadcast?

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.

What is difference between service and broadcast receiver in Android?

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.

Does broadcast receiver work in background?

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.


2 Answers

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

}
like image 53
Ashish John Avatar answered Sep 27 '22 22:09

Ashish John


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
    }
}
like image 44
cristi.onisimi Avatar answered Sep 27 '22 20:09

cristi.onisimi