我希望禁用我附加到boot_completed操作的广播接收器。接收器按预期工作但是我希望在用户禁用我的更新程序时禁用此接收器,详细信息位于https://developer.android.com/training/scheduling/alarms.html的底部。
我尝试使用的代码是:
ComponentName receiver = new ComponentName(context, "com.app.bootcompleted");
PackageManager pm = context.PackageManager;
pm.SetComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DontKillApp);
但是PackageManager不包含: COMPONENT_ENABLED_STATE_ENABLED
在 Xamarin Android 中禁用广播接收器有不同的方法吗?
答案 0 :(得分:1)
我已设法使用以下代码启用/禁用boradcast接收器:
//Stop the boot_complete receiver from starting the alarm
ComponentName receiver = new ComponentName(context, "com.app.bootCompleteReceiver");
PackageManager pm = context.PackageManager;
pm.SetComponentEnabledSetting(receiver, ComponentEnabledState.Disabled, ComponentEnableOption.DontKillApp);
还要确保正确装饰广播接收器:
[BroadcastReceiver (Name = "com.app.bootCompleteReceiver", Enabled = false)]
public class BootCompleteReceiver : BroadcastReceiver { ...