How To Disable The Broadcast Receiver To Stop Receiving The Incoming Calls?
I am facing the issue in disable the broadcast receiver. The broadcast receiver receives the incoming and outgoing calls . In my case when switch is in on the receiver should recei
Solution 1:
Try this, the below code could solve your problem,
switches.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
sharedPreferences = getApplicationContext().getSharedPreferences("enableApp", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(getString(R.string.enable), isChecked);
editor.commit();
if(isChecked)
{
PackageManager pm = DashBoardActivity.this.getPackageManager();
ComponentName componentName = new ComponentName(DashBoardActivity.this, CallReceiver.class);
int status = getApplicationContext().getPackageManager().getComponentEnabledSetting(componentName);
pm.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
Log.e("Broadcast status",status + "");
Toast.makeText(getApplicationContext(), "Enabled", Toast.LENGTH_SHORT).show();
}
else
{
PackageManager pm = DashBoardActivity.this.getPackageManager();
ComponentName componentName = new ComponentName(DashBoardActivity.this, CallReceiver.class);
int status = getApplicationContext().getPackageManager().getComponentEnabledSetting(componentName);
pm.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
Log.e("Broadcast status",status + "");
Toast.makeText(getApplicationContext(), "cancelled", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Disabled", Toast.LENGTH_SHORT).show();
}
}
});
Post a Comment for "How To Disable The Broadcast Receiver To Stop Receiving The Incoming Calls?"