5

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

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Kushan
  • 5,855
  • 3
  • 31
  • 45
  • 1
    @CommonsWare any suggestions? I need the receiver to reset my job scheduler. adding a data tag to the intent filter hasn't helped as it really shouldn't anyway – Kushan Mar 24 '17 at 18:05
  • "any suggestions?" -- I haven't used this `Intent` action much, and I haven't played with this aspect of ODP1 just yet. If you have not done so already, try disabling Instant Run. Also, you might try doing a command-line install via `adb install` and see if the behavior changes, in case this is somehow tied to IDE issues. – CommonsWare Mar 24 '17 at 18:17
  • Alright ya I'll test it out via the adb shell broadcast command. And install that you suggest. Also gonna seperate the two intents into two seperate receivers. Cheers mate thanks – Kushan Mar 24 '17 at 18:22
  • I believe the version code needs to be changed to receive this intent. – M66B Jun 08 '17 at 11:14
  • 1
    I made a seperate receiver with the intent filter and it works now. Apparently, one receiver can only handle one intent filter or something like that... not sure. But seperating the receiver worked for me – Kushan Jun 08 '17 at 19:57

1 Answers1

5

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

Kushan
  • 5,855
  • 3
  • 31
  • 45
  • No need for this. The same intent filter works fine. As [this link](https://stackoverflow.com/a/54212643/2828100) says you have to run `adb install -r`. – funct7 Nov 25 '21 at 22:39