Skip to content Skip to sidebar Skip to footer

Turn On And Off Broadcast Receiver On Button Click In Android

i am doing an sms hiding project which is broadcast receiver the code is given below package com.sms.sms; public class ReceiverClass extends BroadcastReceiver { SQLiteDatabas

Solution 1:

This is only possible if you register your receiver at Activity level(not Manifest) using

registerReceiver(BroadcastReceiver, IntentFilter)

and on the click of the button you can Unregister it using..

unregisterReceiver(BroadcastReceiver receiver)

Edit II

//register button

register.setOnClickListener(newOnClickListener() {

        publicvoidonClick(View v) {

           IntentFilterfilter=newIntentFilter(MY_ACTIVITY);
           Sms2Activityrc=newSms2Activity();
           registerReceiver(rc,filter);

}
    });

//Unregister button

 unregister.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

              unregisterReceiver(rc);

    }
        });

Post a Comment for "Turn On And Off Broadcast Receiver On Button Click In Android"