Is there any way to check if the broadcast receiver is working or not.
I did it like below. I register the broadcast receiver but it doesn't find this registered receiver..
PackageManager pm = getApplicationContext().getPackageManager();
final List<PackageInfo> packs = pm.getInstalledPackages(PackageManager.GET_RECEIVERS);
for (final PackageInfo p : packs) {
ActivityInfo[] receivers = p.receivers;
if (receivers != null) {
for (ActivityInfo ai : receivers) {
if(AppDetectionService.class.getName().equals(ai.name)){
onOff[2] = true;
}
}
}
}
Currently the only way to do this is to call unregisterReceiver(receiver) and catch the IllegalArgumentException that's thrown if it's not registered. Swallow the exception when you get it, you don't need to do anything with it.
I've raised a feature request to Google to get this API added. Please support it here: https://code.google.com/p/android/issues/detail?id=73718
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