Why MY_PACKAGE_REPLACED Android action is ignored by the content scheme
Asked Answered
A

2

5

I have a intent-filter declaration in the manifest for a broadcast.

       <intent-filter>
            <action android:name="android.intent.action.TIME_SET"/>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
            <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
            <data android:scheme="content"/>
        </intent-filter>

The problem is when I remove the <data android:scheme="content"/> the MY_PACKAGE_REPLACED action is received otherwise no.

What does the data tag in this case? Can't really understand from the documentation.

Aguilera answered 2/9, 2016 at 14:41 Comment(0)
Q
8

The <data> element says "there must be a Uri on the Intent, and it must match the rules provided in the <data> elements of the <intent-filter>". In your particular case, the rule is "the Uri must exist and it must have a content scheme".

Since none of those three broadcasts uses a content Uri, delete the <data> element.

Quell answered 2/9, 2016 at 14:52 Comment(0)
E
6

for MY_PACKAGE_REPLACED, you just use this:

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



public class UpgradeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, Intent intent) {
        if (!Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction()))
            return;
    ...  
    }
}

Also, make sure you run the app while instant-run is disabled, as noted here. I've noticed it doesn't always get received if it's enabled...

Europeanize answered 10/6, 2018 at 15:49 Comment(6)
Its running in debug mode, i.e. UpgradeReceiver onReceive called. But in release apk it's not working. any suggestion?Dives
@GiruBhai Should work. If not, it's either because of instant-run, or because the user chose "force stop" or similar.Europeanize
I had tested with two release apksDives
Test better. Write to the logs using log.e("something") , for example. I've tested it now. Works well, unless you've never started the app.Europeanize
release is proguarded, keep the name of the boradcastReceiver in your proguard files, it should be the first check to make for your "not running in prod" problem..Unmeasured
@MathiasSeguyAndroid2ee I don't think you need it in proguard rules. It should be available anyway, just like Activity, Service, etc... I don't see it in my custom list. I think it's in the default one.Europeanize

© 2022 - 2024 — McMap. All rights reserved.