Now that the final API for Android O is released and none of the following broadcasts is whitelisted I have the following problem:
In my application (targets API 25) I currently have a BroadcastReceiver
which listens for system events of ACTION_POWER_CONNECTED
and ACTION_POWER_DISCONNECTED
. Now I would like to update my app to target Android O but with this release comes a huge change in broadcast behaviors:
Apps that target Android O can no longer register broadcast receivers for implicit broadcasts in their manifest. An implicit broadcast is a broadcast that does not target that app specifically.
Since both broadcasts are implicit I can only register for them via the Context.registerReceiver()
method but with this comes the problem: As soon as the process of my app is killed by the system or as soon as system clears my app's memory (as a result of low-memory of device) the broadcast registration will be lost.
To avoid this problem I can use the JobScheduler
API with the setRequiresCharging
method for ACTION_POWER_CONNECTED
but for ACTION_POWER_DISCONNECTED
I have to use the registerReceiver
method.
Since my app controls the volume of the device (based on these events) it's really important that none of these events is missed. So how can I safely listen for disconnected power events in Android O?
Btw. I have the same problem with WIFI disconnect events.
EDIT: I would love to do this without a notification from a foreground service