我希望通知会在早上8点出现。在上午8点运行警报,我错过了什么?
notificationIntent.putExtra(MyAlarmReceiver.ALARM_ID, alarmID);
notificationIntent.putExtra(MyAlarmReceiver.ALARM_TITLE, notifTitle);
notificationIntent.putExtra(MyAlarmReceiver.ALARM_SUBTITLE, subTitle);
notificationIntent.putExtra(MyAlarmReceiver.NOTIFICATION_TAG, notificationTag);
notificationIntent.putExtra(MyAlarmReceiver.NOTIFICATION_ID, notifId);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
final int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk > android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
}
答案 0 :(得分:0)
该平板电脑上使用的Android版本很可能是Marshmallow或更新版本(API 23)。为了触发警报,您必须通过调用alarmManager.setExactAndAllowWhileIdle()
将其从Doze(空闲模式)优化中排除。