Android - how to set an alarm to a specific date

后端 未结 3 746
故里飘歌
故里飘歌 2020-11-30 01:08

I have seen a lot of tutorials and been trying for 2 hours now , though something is still wrong. I am very nervous now :) I want to set an alarm e.g. to 16:25 to go off, bu

3条回答
  •  离开以前
    2020-11-30 01:59

    Usually you shouldn't obtain Calendar like you do, there is Calendar.getInstance() method for that:

    Calendar cal = Calendar.getInstance();
    

    That gives you a calendar with all fields set to current date, then just:

    cal.set(Calendar.HOUR_OF_DAY, 16);
    cal.set(Calendar.MINUTE, 25);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    
    alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
    

提交回复
热议问题