无法接收PACKAGE意图的广播

Jam*_*mes 5 android

我正在尝试注册广播接收器以接收包事件的广播事件.以下是清单文件中的代码和接收器.日志状态永远不会发生,但我可以清楚地看到"HomeLoaders"(Launcher)调试语句的相同广播触发.我错过了什么?

public class IntentListener extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Log.i("INTENT LISTNER:", intent.getAction());
    }
}

<receiver android:name="IntentListener" android:enabled="true" android:exported="true">
    <intent-filter>
        <data android:scheme="package"></data>
        <action android:name="android.intent.action.PACKAGE_ADDED"></action>
        <action android:name="android.intent.action.PACKAGE_ADDED"></action>
        <action android:name="android.intent.action.PACKAGE_CHANGED"></action>
    </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)

Com*_*are 4

这些 s 可能Intent无法被清单中注册的组件接收,而只能被 Java 中通过registerReceiver().

  • 正如我大约一天前评论过另一个 SO 问题一样,Android 不一定希望一直启动一个新组件。我知道的一种情况是电池事件(例如,ACTION_BATTERY_LOW)。看起来 SCREEN_OFF(也许还有 SCREEN_ON)是其他的。如果你想到了这一点,并且你让它与 registerReceiver() 一起工作,请回应这个问题。我认为我需要在博客文章和/或书籍部分中介绍这个主题,不幸的是,无清单接收者意图列表没有记录。 (3认同)