With the two type of broadcast implicit
and explicit
broadcast in Android - for the implicit we would declare the broadcast in AndroidManifest.xml
and when some app sends a broadcast with the action the all the apps which declares the broadcast in their manifest with that action would get invoked and do the job.
With the background execution limits imposed by Android from O, I'm not allowed to send a broadcast only with the intent containing action
. I must specify explicitly the package name and the receiving class name.
Now by doing something like this, I'm able to overcome the implicit broadcast limitation
String action = "com.android.intent.CUSTOM";
Intent intent = new Intent();
intent.setAction(intent);
//Though this is a deprecated method
List<ResolveInfo> resolvedBroadcasts = List<ResolveInfo> queryBroadcastReceivers(intent, 0, current_user_id);
for (ResolveInfo info : resolvedBroadcasts) {
ServiceInfo serviceInfo = info.serviceInfo;
//Note: Now this is becoming explicit broadcast
intent.setAction(serviceInfo.packageName, serviceInfo.name);
context.sendBroadcast(intent);
}
Am I missing something here? Got confused at this point like if I'm able to do this way then why Android imposed me this background execution limits?