Open ferrannp opened 6 years ago
Did you find a solution? I am wondering the same.
Hey, yes. I have my own RegisterFenceAction
and uses the pending intent like:
static PendingIntent createPendingIntent(Context context, int requestCode, @Nullable Bundle data) {
// Custom one due: https://github.com/Mauin/ReactiveAwareness/issues/11
return PendingIntent.getBroadcast(context, 0,
new Intent(context, BackgroundFenceReceiver.class), 0);
}
For what I understand, even with the background limitations introduced in Android O https://developer.android.com/about/versions/oreo/background, we should still be able to use AwarenessAPI to receive broadcast even with the app in the background.
Anything special we need to do? I am trying to listen for headphones in the background.
It looks like the problem is the way the PendingIntent is created: https://github.com/Mauin/ReactiveAwareness/blob/a2f4701159e92d9206549fb5faba9bbe4a8c8e37/reactiveawareness-fence/src/main/java/com/mtramin/reactiveawarenessfence/FenceReceiver.java#L60
I copied/pasted some of your files and create the intent explicitly like here https://stackoverflow.com/a/46390123/2277631.
And it works.