Unregister a broadcast receiver registered through the manifest

Can I unregister a BroadcastReceiver registered through a manifest? Also let me know if BroadcastReceiver can be ignored without making any code changes since I don't need this BroadcastReceiver now. Thanks.

+6
source share
1 answer

You can disconnect the receiver with this code:

 PackageManager pm = getPackageManager(); ComponentName compName = new ComponentName(getApplicationContext(), MyReceiver.class); pm.setComponentEnabledSetting( compName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); 

You can also use COMPONENT_ENABLED_STATE_ENABLED to turn on the receiver.

+6
source

All Articles