Mauin / ReactiveAwareness

Android library to quickly and easily get the users context using the Awareness API and RxJava
Apache License 2.0
20 stars 2 forks source link

From Android O "W/BroadcastQueue: Background execution not allowed: receiving Intent { act=ReactiveAwarenessFence flg=0x10 (has extras) }" #11

Open ferrannp opened 6 years ago

ferrannp commented 6 years ago

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.

IgorGanapolsky commented 5 years ago

Did you find a solution? I am wondering the same.

ferrannp commented 5 years ago

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);
}
leehong2005 commented 3 years ago

https://commonsware.com/blog/2017/04/11/android-o-implicit-broadcast-ban.html