0

Why is it that I can register a broadcast receiver for "android.intent.action.ACTION_POWER_CONNECTED" via the manifest file but not programmatically using the following:

    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction("android.intent.action.ACTION_POWER_CONNECTED");
    registerReceiver(powerStateListener, iFilter);

What is the best way to determine which intents must be registered for via the manifest and which can be done programmatically?

4

1 回答 1

3

不幸的是,这里的文档有点迟钝。它实际上只记录在ACTION_BATTERY_CHANGED

您不能通过清单中声明的​​组件接收此信息,只能通过使用 Context.registerReceiver() 显式注册它。请参阅 ACTION_BATTERY_LOW、ACTION_BATTERY_OKAY、ACTION_POWER_CONNECTED 和 ACTION_POWER_DISCONNECTED,了解发送和可通过清单接收器接收的不同电池相关广播

因此,据我了解文档, ACTION_BATTERY_CHANGED 只能由注册的接收者接收,而 ACTION_POWER_CONNECTED 只能由清单中指定的接收者接收。

于 2013-05-28T03:30:09.823 回答