X-HuMan
X-HuMan

Reputation: 1488

Why MY_PACKAGE_REPLACED Android action is ignored by the content scheme

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.

Upvotes: 5

Views: 6353

Answers (2)

android developer
android developer

Reputation: 116352

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...

Upvotes: 6

CommonsWare
CommonsWare

Reputation: 1006664

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.

Upvotes: 8

Related Questions