0

I use setAlarmClock but delay from the set time.

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);
    }

Calendar function

 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;
}

I test with pure android M. And time delay about 3-5 minutes.

Thankyou and Sorry for bad english

0 Answers0