Broadcast battery declared in manifest file not working?

There are two ways to make a broadcast receiver known to the system: one declares it in the manifest file using this element. Another task is to create a speaker in Java code.

Now the recipient is dynamically created in Java code, and it works fine. But why the first way to "Declare in the manifest file" failed?

Is there anyone for success?

Thank.

AndroidManifest.xml

<receiver android:name="pj.batteryinfo.BatteryReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BATTERY_CHANGED"></action>
    </intent-filter>
</receiver>
+5
source share
1 answer

For some actions, you can only declare BroadcastReceiver in Java code. This occurs with the action BATTERY_CHANGED, and SCREEN_ON, SCREEN_OFFas far as I know.

BroadcastReceiver Manifest.xml, , , BroadcastReceiver , , , onReceive.

? , , BATTERY_CHANGED , , , , , , , , , , . , Android .

. . , , , .

+4

All Articles