0

I am creating broadcast receiver and calling from an activity. dynamically i want to check the broadcast receiver is registered or not so that i can unregister the broadcast receiver? Thanks in advance

Prem kumar adepu
  • 181
  • 2
  • 13

2 Answers2

1

Please check the link below for the answer. Their you can see a short nice answer:

Unregistering Android Broadcast Receiver in onReceive throws "Receiver not registered"

Community
  • 1
  • 1
zennon
  • 1,080
  • 10
  • 25
0

have this code to enable and disable the broadcast receiver using package manager: This code works like Toggle button.

int flag = (enabled ?
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED);

            if(flag == 1)
                flag = 2;
            else
                flag = 1;

            Log.d("After Flag","::"+flag);

            ComponentName component = new ComponentName(StartActivity.this, SMSReceiver.class);

            getPackageManager().setComponentEnabledSetting(component, flag,PackageManager.DONT_KILL_APP);

Where enable is Boolean which I have saved as shared preference to know whether the last time my broadcast receiver was working or not.

Caution Continues
  • 743
  • 2
  • 10
  • 25