I can't receive broadcast on battery state change?

Solution 1:

From the documentation for ACTION_BATTERY_CHANGED:

You can not receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver(). See ACTION_BATTERY_LOW, ACTION_BATTERY_OKAY, ACTION_POWER_CONNECTED, and ACTION_POWER_DISCONNECTED for distinct battery-related broadcasts that are sent and can be received through manifest receivers.

There you have it: you must explicitly register for it from your Java code.

Solution 2:

I just followed the Android Developer Guide's on Monitoring the Battery Level and Charging State and had immediate success. If BatteryLevelReceiver is it's own class then I would recommend:

<receiver android:name=".BatteryLevelReceiver">
    <intent-filter android:priority="900">
       <action android:name="android.intent.action.BATTERY_LOW" />
       <action android:name="android.intent.action.BATTERY_CHANGED" />
    </intent-filter>
</receiver>

Addition

I'm willing to guess that you wrote BatteryLevelReceiver as a nested class in ReceversAndServices. According to Receiver as inner class in Android, you cannot do that with non-static classes. You could make BatteryLevelReceiver a static class and register the receiver in onResume(), but then your app will need to be running to catch the events... Move your receiver to a separate class and register these Intents:

<receiver android:name=".BatteryLevelReceiver">
    <intent-filter android:priority="900">
       <action android:name="android.intent.action.BATTERY_LOW" />
       <action android:name="android.intent.action.BATTERY_OKAY" />
       <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
       <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
    </intent-filter>
</receiver>

(Not BATTERY_CHANGED as Darshan Computing pointed out.)