为什么 MY_PACKAGE_REPLACED Android 动作被内容方案忽略

Why MY_PACKAGE_REPLACED Android action is ignored by the content scheme

我在广播的清单中有一个 intent-filter 声明。

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

问题是当我删除 <data android:scheme="content"/> 时收到 MY_PACKAGE_REPLACED 操作,否则不会。

这种情况下的数据标签是什么?无法从文档中真正理解。

<data> 元素表示 "there must be a Uri on the Intent, and it must match the rules provided in the <data> elements of the <intent-filter>"。在您的特定情况下,规则是 "the Uri must exist and it must have a content scheme".

因为这三个广播中的 none 使用 content Uri,删除 <data> 元素。

对于MY_PACKAGE_REPLACED,你只需使用这个:

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

此外,请确保您 运行 在禁用即时 运行 的应用程序时,如前所述 here。我注意到如果启用它并不总能收到...