I am facing some problems with the implementation of an always running Broadcast Receiver on API 26. First of all, my Intent Filters are not on the whitelist of Oreo's no restriction-Intent Filters. I tried wrapping my Broadcast Receiver in a NotificationListenerService, but it gets killed after some time. Furthermore, I don't want to make the Foreground Service notification show. If I downgrade my TargetSDK to API 25, these restrictions won't be enabled on Oreo devices? Thank you :)
-
"If I downgrade my TargetSDK to API 25, these restrictions won't be enabled on Oreo devices?" -- any user who wants to can still apply those background restrictions on your app. It's just manual, rather than automatic. – CommonsWare Nov 21 '17 at 11:41
2 Answers
A BroadcastReceiver
has limited time to handle an incoming broadcast:
there is a timeout of 10 seconds that the system allows before considering the receiver to be blocked and a candidate to be killed
If by "Always running" you actually meant "Implicitly registered", as in, a broadcast that is always registered, even when the app is not running, then you can set your targetSDK to not target 24 or below, and it should be ok, unless an Oreo user goes into settings, and enforces the new limitations on your app.
From the docs:
Apps cannot use their manifests to register for most implicit broadcasts
...
By default, these restrictions only apply to apps that target O. However, users can enable these restrictions for any app from the Settings screen, even if the app has not targetted O.

- 27,641
- 11
- 107
- 150
-
So, would you suggest me to downgrade my app target to SDK 25 and register the Broadcast Receiver inside my Application Manifest so that it's always registered? Thanks so much! – user3424279 Nov 21 '17 at 10:31
-
it's not a future proof solution because one day you might need to increase your target again because of some dependency, but yeah, that's what I would do at the moment – marmor Nov 21 '17 at 11:44
-
That's bad, I don't know why they restricted background services THIS much. Aren't there other ways to stay on API 26 and make the Receiver always registered? – user3424279 Nov 21 '17 at 11:46
If it can help, this solution did work for me (if your broadcast receiver is registered in the manifest of your app or another app):
PackageManager pm=getPackageManager();
List<ResolveInfo> matches=pm.queryBroadcastReceivers(yourIntent, 0);
for (ResolveInfo resolveInfo : matches) {
Intent explicit=new Intent(yourIntent);
ComponentName cn= new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName,
resolveInfo.activityInfo.name);
explicit.setComponent(cn);
sendBroadcast(explicit);
}

- 824
- 1
- 9
- 21