Search code examples
androidbroadcastreceiverandroid-manifest

Checking if a BroadcastReceiver is declared in the manifest in runtime?


Is there a way to check which BroadcastReceivers are declared in the manifest, in runtime?


Solution

  • Thanks, but was not my intention... I wanted to get know if a specific receiver is declared in the running application in runtime, and achieved it like this:

        private <Receiver extends CyborgReceiver<?>> boolean checkIfBroadcastReceiverIsRegisteredInManifest(Class<Receiver> receiverType) {
        PackageManager pm = application.getPackageManager();
        try {
            ActivityInfo info = pm.getReceiverInfo(new ComponentName(application, receiverType), PackageManager.GET_RECEIVERS);
            return info.enabled;
        } catch (NameNotFoundException e) {
            return false;
        }
    }