我从这里得到了禁用/启用广播接收器的逻辑。
@Override
public void onCheckedChanged(CompoundButton v, boolean checked) {
// TODO Auto-generated method stub
if (v == disableBlock) {
manageBlockSetting(checked);
}
}
private void manageBlockSetting(boolean disable) {
Log.e(tag, "Disable : " + disable);
int flag = disable ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
: PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
ComponentName component = new ComponentName(SettingActivity.this, PhoneCallReceiver.class);
getApplication().getPackageManager().setComponentEnabledSetting(component, flag, PackageManager.DONT_KILL_APP);
editSharedPreferences(StoreConstantValue.SETTING_DISABLE_BLOCK, disable);
}
在 Manifest.xml 中
<receiver android:name="com.vsmart.unocaller.blockingservice.PhoneCallReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
当我部署时android:enabled="false"
我可以启用它一次。但是当我想禁用时。没有任何反应,我无法禁用它。它仍然阻止来电。
我的设备是带有 Android 2.3.3 的三星 Galaxy S2
有什么帮助吗?谢谢