因此,我有一个应用程序,这是基于重复的任务使用AlarmManager,我想要初始化警报,如果设备是重新启动
因此,我做了一个引导接收器,前面的代码:
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Log.Write("BootCompleted Alarm was received.");
Alarms.Init(context);
}
}我还使用以下命令获得了权限:
[assembly: UsesPermission(Manifest.Permission.ReceiveBootCompleted)]在我的设备设置中检查应用程序的权限时,它具有权限。
那么,它为什么不能点火呢?
发布于 2020-08-11 10:34:33
当您注册接收基于系统事件的广播时,新api中的一些限制会导致问题(例如,AlarmManager)
在文档Statically registering a Broadcast Receiver with an Intent Filter中
在Android8.0(API26和更高版本)中的
,Google placed limitations关于当用户不直接与应用程序交互时应用程序可以做什么。这些限制会影响后台服务和隐式广播接收器,如Android.Content.Intent.ActionBootCompleted。由于这些限制,您在较新版本的Android上注册Boot Completed broadcast receiver时可能会遇到困难。如果是这种情况,请注意,这些限制不适用于前台服务,可以从广播接收器调用前台服务。
https://stackoverflow.com/questions/63345848
复制相似问题