Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if the broadcstreceiver is registered? [duplicate]

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;
                }
            }
        }                   
    }
like image 743
aysbtl_ Avatar asked Dec 02 '13 13:12

aysbtl_


1 Answers

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

like image 164
ojf Avatar answered Sep 18 '22 09:09

ojf