警报管理器不适用于Android版本9

时间:2019-06-26 06:51:05

标签: android alarmmanager android-9.0-pie

该应用程序的要求是在任何指定时间触发警报并在该特定时间执行指定任务。 为此,我使用了AlarmManager。但这不适用于Android版本9。

我使用了可在Android 7.0版上运行的Alarm Manager。

我使用了setInexactRepeating()的{​​{1}}方法。

我尝试使用以下代码进行操作:

AlarmManager

我希望AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);必须在Android 9的指定时间被​​触发。

1 个答案:

答案 0 :(得分:-1)

感谢大家花时间回答我的问题。我真的很感激。

这就是我解决此问题的方法:

如果(Build.VERSION.SDK_INT

am.set(AlarmManager.RTC_WAKEUP, stopTrackingAtMidnight, PendingIntent);

其他

am.setExact(AlarmManager.RTC_WAKEUP, stopTrackingAtMidnight, PendingIntent);

setExact()方法对我有用!