Search code examples
androidbattery

ACTION_BATTERY_LOW not being fired from manifest?


Does action_battery_low allow being fired from the manifest because I thought it did?

Here is my manifest for it:

<reciever android:name=".BatteryReciever">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.BATTERY_LOW"/>
    </intent-filter>
</reciever>

But it never gets fired when I get the low battery warning from the system. Can this only be fired explicitly?


Solution

  • The original question states that the receiver does not receive intents. This is because the receiver was declared as <reciever> rather than <receiver>. Had the receiver element been declared correctly, it would have worked.

    Another major source of confusion is the fact that the Android documentation incorrectly references "android.intent.action.ACTION_BATTERY_LOW" and "android.intent.action.ACTION_BATTERY_OKAY". There is an existing Android Issue for this documentation error, but you should be aware that some of the comments on that issue are misleading.

    Instead, the receiver's actions must be "android.intent.action.BATTERY_LOW" and "android.intent.action.BATTERY_OKAY". When referencing these actions from Java source, you may use the constants android.content.Intent.ACTION_BATTERY_LOW and android.content.Intent.ACTION_BATTERY_OKAY which are defined correctly.

    Unfortunately Reto Meier also incorrectly defines the action in A Deep Dive Into Location. An issue has been filed for this as well.