So I need a way to find out if there is a broadCastReceiver registered for a specific action string.
So to check if intent is available we have method (from http://www.vogella.com/articles/AndroidIntent/article.html)
public boolean isIntentAvailable(Context context, String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List<ResolveInfo> resolveInfo =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfo.size() > 0) {
return true;
}
return false;
}
Which works but from my tests looks only for intents that activities are registered to. I have a broadCastReceiver registered for a specific action string. and it never sees it as registered. But if I fire broadcast. broadcast reacts. So method don't work in this case.
Ideas?
try {
if (sendBroadcastReceiver != null) {
this.unregisterReceiver(sendBroadcastReceiver);
}
} catch (IllegalArgumentException e) {
sendBroadcastReceiver = null;
}
It's almost the same, for broadcast receivers you should call PackageManager#queryBroadcastReceivers
.
public abstract List<ResolveInfo> queryBroadcastReceivers (Intent intent, int flags)
Since: API Level 1
Retrieve all receivers that can handle a broadcast of the given intent.
Parameters
intent The desired intent as per resolveActivity().
flags Additional option flags.
Returns
A List<ResolveInfo> containing one entry for each matching Receiver. These are ordered from first to last in priority. If there are no matching receivers, an empty list is returned.
Look at the docs, to see what else can you get.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With