7

Is it possible to unregister a BroadcastReceiver that has been registered through manifest? Also please let me know if it possible to ignore the BroadcastReceiver, without making any code changes, as this BroadcastReceiver is of no use to me now. Thanks.

faceman
  • 1,318
  • 11
  • 20
Mayur More
  • 951
  • 2
  • 15
  • 37
  • 2
    You can enable and disable it on the Manifest and programmatically enable and disable it as well...see this answer: http://stackoverflow.com/questions/5624470/enable-and-disable-a-broadcast-receiver – Alécio Carvalho Mar 25 '13 at 09:03
  • 2
    yes you can use `getPackageManager().setComponentEnabledSetting` for enabling or disabling broadcast receiver at runtime see [Enable and disable a Broadcast Receiver](http://stackoverflow.com/questions/5624470/enable-and-disable-a-broadcast-receiver) – ρяσѕρєя K Mar 25 '13 at 09:04

1 Answers1

6

You can disable 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);

Also you can use COMPONENT_ENABLED_STATE_ENABLED to enable Receiver.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841