X-H*_*Man 4 android broadcast intentfilter
我在广播清单中有一个意图过滤器声明。
<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>
Run Code Online (Sandbox Code Playgroud)
问题是,当我删除<data android:scheme="content"/>了MY_PACKAGE_REPLACED行动收到否则就没有。
在这种情况下数据标签是什么?从文档中无法真正理解。
对于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;
...
}
}
Run Code Online (Sandbox Code Playgroud)
另外,请确保在禁用即时运行时运行应用程序,如此处所述。我注意到,如果启用它,并不总是会收到它......
该<data>元素说“必须有一个Uri在Intent,而且必须在提供的规则匹配<data>的元素<intent-filter>”。在您的特定情况下,规则是“Uri必须存在并且必须有content方案”。
由于这三个广播都没有使用 a content Uri,请删除该<data>元素。
| 归档时间: |
|
| 查看次数: |
3768 次 |
| 最近记录: |