我使用的AlarmManager如下所示,它对Android O和以下操作系统运行良好。
AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(context, PeriodicChecksService.class);
PendingIntent pi=PendingIntent.getService(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + firstGoOffTime, frequencyInMS , pi);
但在android p中,am在logcat中得到以下错误:
不允许后台启动:服务意图{flg=0x4
cmp=com.app.appname/.periodicchecksservice(has extras)}到
com.app.recorder/.periodicchecksservice from pid=-1 uid=10321
pkg=com.app.appname开始吗?=假
我相信这是因为我们必须使用
startForegroundService
启动服务时。我们在AlarmManager中如何做到这一点?