如何在同一天多次触发警报?

时间:2016-08-26 10:14:37

标签: android alarmmanager android-pendingintent android-alarms

例如,第一次警报将在上午10:00触发,第二次警报将在上午11:15触发,第三次警报将在上午11:45触发....就像这样,每个实例之间没有任何共同点,我需要多次触发警报。

如果我有共同的区别,可以使用重复功能,但没有时间之间的共同区别我需要触发它。那么,如何多次触发警报?

2 个答案:

答案 0 :(得分:0)

You can set multiple alarm

Calendar calendar1 = Calendar.getInstance();
            calendar1.set(Calendar.HOUR_OF_DAY, HOUR_1);
            calendar1.set(Calendar.MINUTE, MINUTES);
            calendar1.set(Calendar.SECOND, SEC);

            Calendar calendar2 = Calendar.getInstance();
            calendar2.set(Calendar.HOUR_OF_DAY, HOUR_2);
            calendar2.set(Calendar.MINUTE, MINUTES);
            calendar2.set(Calendar.SECOND, SEC);

            Calendar calendar3 = Calendar.getInstance();
            calendar3.set(Calendar.HOUR_OF_DAY, HOUR_3);
            calendar3.set(Calendar.MINUTE, MINUTES);
            calendar3.set(Calendar.SECOND, SEC);

            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar1.getTimeInMillis(), ALARM_INTERVAL , pendingIntent1);//here interval is 24*60*60*1000
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar2.getTimeInMillis(), ALARM_INTERVAL , pendingIntent2);//24*60*60*1000
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar3.getTimeInMillis(), ALARM_INTERVAL , pendingIntent3);//24*60*60*1000

    }

答案 1 :(得分:0)

来自此链接&#34; http://www.satyakomatineni.com/item/3503&#34; ,ArrayList<Calendar>calenderList=new ArrayList<Calendar(); calender=Calendar.getInstance(TimeZone.getDefault(),Locale.getDefault()); calender.set(Calendar.DATE,resultDay); calender.set(的Calendar.MONTH,8); calender.set(Calendar.YEAR,2016); calender.set(Calendar.HOUR_OF_DAY,14); calender.set(Calendar.MINUTE,30); calender.set(Calendar.SECOND,10);

for(int n=0;n<calenderList.size();n++)      
PendingIntent pendingIntent = PendingIntent.getBroadcast(

Intent intent = new Intent(TvActivity.this,TVAlarmReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                this.getApplicationContext(),n, intent,PendingIntent.FLAG_UPDATE_CURRENT);          AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);         alarmManager.setExact(AlarmManager.RTC_WAKEUP,calenderList.get(n).getTimeInMillis(), pendingIntent);