Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broadcast receiver does not get MY_PACKAGE_REPLACED intent

As per the Android O developer preview, we can no longer use the PACKAGE_REPLACED intent to use with a receiver declared inside the manifest.

The alternative is MY_PACKAGE_REPLACED. But this intent does not seem to fire when i update the app via android studio after code changes. Whereas the old broader intent always fired properly.

    <receiver
        android:name=".Receivers.BootEventReceiver"
        android:exported="true"
        android:enabled="true">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
        </intent-filter>
    </receiver>

assume that the receiver itself just prints a log message in onReceive().

Googling suggested this seems to be some android manifest merger issue. But i really couldn't follow how to solve this.

Can someone point me in the right direction

like image 975
Kushan Avatar asked Mar 24 '17 17:03

Kushan


People also ask

What is the difference between intent and broadcast receiver?

An intent is a messaging object, a broadcast receiver is an app component. An intent is used to request some action from some app component, it could be a broadcast receiver, an activity or a service.

How do you broadcast custom intents?

Sending Broadcast intents from the Activity Intent intent = new Intent(); intent. setAction("com. journaldev. CUSTOM_INTENT"); sendBroadcast(intent);

What is intent How are they used to broadcast and receive events?

Android uses Broadcast Intents extensively to broadcast system events like battery-charging levels, network connections, and incoming calls. Broadcasting Intents is actually quite simple. Within your application component, construct the Intent you want to broadcast, and use the sendBroadcast method to send it.


1 Answers

Instead of having one receiver with two intent filters, i decided to make a separate receiver with MY_PACKAGE_REPLACED intent filter.

The receiver started working again. Hope this helps anyone interested

like image 122
Kushan Avatar answered Oct 22 '22 23:10

Kushan