如何在android M中设置报警管理器

时间:2016-09-05 10:00:32

标签: android alarmmanager android-alarms

我使用setAlarmClock但是从设定时间延迟。

mycode的

    Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    intent.putExtra(AppConstant.REMINDER, note.convertToString());
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),
            note.getId(), intent, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(getTargetTime().getTimeInMillis(),pendingIntent),pendingIntent);
    }

日历功能

 private Calendar getTargetTime() {
    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();
    calSet.set(Calendar.DAY_OF_MONTH, sDay);
    calSet.set(Calendar.HOUR_OF_DAY, sHour);
    calSet.set(Calendar.MINUTE, sMinute);
    calSet.set(Calendar.SECOND, 0);
    calSet.set(Calendar.MILLISECOND, 0);

    return calSet;
}

我用纯机器人M进行测试。时间延迟约3-5分钟。

谢谢你,抱歉英文不好

0 个答案:

没有答案