Android alarm setting with specific date

前端 未结 4 2278
刺人心
刺人心 2020-12-11 09:17

I wan to set alarm with notification at specific date. Then I am using AmarmManager with NotificationManager currently. When I set selected date from dateDialog, the alarm i

4条回答
  •  情书的邮戳
    2020-12-11 10:08

    Hey this is how to set alarm on android AlarmManager to spesific date (android alarmmanager set alarm on date) I have been searching all over for this. pay attention to the value of the month!!

    Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
    //cal.add(Calendar.SECOND, 10);
    
    cal.set(Calendar.DATE,19);  //1-31
    cal.set(Calendar.MONTH,Calendar.DECEMBER);  //first month is 0!!! January is zero!!!
    cal.set(Calendar.YEAR,2012);//year...
    
    cal.set(Calendar.HOUR_OF_DAY, 16);  //HOUR
    cal.set(Calendar.MINUTE, 39);       //MIN
    cal.set(Calendar.SECOND, 10);       //SEC
    
    
    // Create a new PendingIntent and add it to the AlarmManager
    Intent intent = new Intent(MainActivity.this, alarmAct.class);
    PendingIntent pendingIntent = PendingIntent.getService(MainActivity.this, 0,intent, 0);
    
    //or if you start an Activity
    //PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0,intent, 0);
    
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
    

提交回复
热议问题