If you want to have multiple repeating alarms, you need to use multiple
alarms -- that is multiple distinct pending intents, since that is what
identifies the alarm.

On Fri, Sep 4, 2009 at 2:11 PM, GilBF <[email protected]> wrote:

>
> im trying to build an alarm within my app with codes like below but it
> does not work with a loop having multiple days.
>
> it seems like setRepeatingAlarm can not be fired with multiple
> triggerAtTime values. it only works to repeat the alarm with one
> TiggeratTime and an interval time
>
> AlarmManager am[] = new AlarmManager[6] ;
> PendingIntent mAlarmSender[] = new PendingIntent[6] ;
>
> cnt = 6 /* Mon to Sun* or if Mon or any single day only/
> mDays[i]  = can be from Mon to Sun or just Mon(one day only)
>
> for (int i= 0; i < cnt ; i++)
> {
>     am[i] = (AlarmManager)getSystemService(ALARM_SERVICE);
>     firstTime = setAlarmTime(mDays[i], mHour, mMinute,
> sAmPm) ;
>     am[i].setRepeating(AlarmManager.RTC_WAKEUP, firstTime, intrvl,
> mAlarmSender[i]);
> }
>
> private static long setAlarmTime(String mDay, int mHour, int mMinute,
> String sAmPm) {
>        /* Compare the current calendar time with the time set by user */
>        String calAmPm ;
>        int mDayNumber = 0 ;
>        int hrDiff = 0 ;
>        int minDiff = 0 ;
>
>        mDayNumber = convertToDayNumber(mDay) ;
>
>        Calendar calendar = Calendar.getInstance();
>        calendar.setTimeInMillis(System.currentTimeMillis());
>        int mDy  = calendar.get(Calendar.DAY_OF_WEEK);
>        int mHr  = calendar.get(Calendar.HOUR);
>        int mMin = calendar.get(Calendar.MINUTE);
>        int mAP = calendar.get(Calendar.AM_PM);
>
>        if ( mAP == 0 )
>                calAmPm = "AM" ;
>        else
>                calAmPm = "PM" ;
>
>        if (sAmPm.compareTo(calAmPm) == 0)
>        {
>            if (mHour > mHr)
>                /*user entered alarm time is 9:00PM vs  phone time of
> 5:00PM */
>                hrDiff = mHour - mHr ;     //4
>            else if (mHour < mHr)
>                /* 9:00PM 11:00PM*/
>                hrDiff = 24 - (mHr - mHour) ;
>            else
>                hrDiff = 0 ;
>
>                if (mMinute > mMin)
>                        /* 9:30PM vs 5:15PM */
>                minDiff = mMinute - mMin ;         //15
>            else if (mMinute < mMin)
>                /* 9:10PM 11:15PM */
>                minDiff = 60 - (mMin - mMinute) ; //55
>            else
>                minDiff = 0 ;
>        }
>        else if (sAmPm.compareTo("PM") == 0 && calAmPm.compareTo("AM")
> == 0 ) {
>                /* 9:00PM vs 5:00AM  9:00PM 11:00AM*/
>                if (mHour > mHr)
>                hrDiff = 12 + (mHour - mHr) ;     //16
>            else if (mHour < mHr)
>                hrDiff = 12 - (mHr - mHour) ; //10
>            else
>                hrDiff = 0 ;
>
>                /* 9:30PM vs 5:15PM  9:10PM 11:15PM*/
>                if (mMinute > mMin)
>                minDiff = mMinute - mMin ;         //15
>            else if (mMinute < mMin)
>                minDiff = 60 - (mMin - mMinute) ; //55
>            else
>                minDiff = 0 ;
>        }
>        else if (sAmPm.compareTo("AM") == 0 && calAmPm.compareTo("PM")
> == 0 ) {
>                /* 9:00AM vs 5:00PM  9:00AM 11:00PM*/
>                if (mHour > mHr)
>                        hrDiff = 12 + (mHour - mHr) ;     //16
>                else if (mHour < mHr)
>                        hrDiff = 12 - (mHr - mHour) ; //10
>                else
>                        hrDiff = 0 ;
>
>                /* 9:30PM vs 5:15PM  9:10PM 11:15PM*/
>                if (mMinute > mMin)
>                        minDiff = mMinute - mMin ;         //15
>                else if (mMinute < mMin)
>                        minDiff = 60 - (mMin - mMinute) ; //55
>                else
>                        minDiff = 0 ;
>        }
>        /* this add means were adding the hour and min diff of the user
> entered time with the current time */
>        if (hrDiff == 1 && minDiff > 0)
>                calendar.add(Calendar.HOUR,0);
>        else
>                calendar.add(Calendar.HOUR,hrDiff);
>
>        calendar.add(Calendar.MINUTE,minDiff);
>        calendar.add(Calendar.DAY_OF_WEEK,getDayDiff(mDayNumber, mDy));
>
>        /* since we have added new values for day, hours and min needed
> to our current calendar time, get             its            long
> value */
>        return calendar.getTimeInMillis() ;
>  }
>
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to