Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to repeat alarm week day on in android

I want to get alarm on monday to friday only. my code is here

if (chk_weekday.isChecked()) {

                    int day = calNow.get(Calendar.DAY_OF_WEEK);
                    if (day == 2 || day == 3 || day == 4 || day == 5
                            || day == 6) {

                        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                                calSet.getTimeInMillis(), 1 * 60 * 60 * 1000,
                                pendingIntent);

                    }

Have a Idea.

like image 630
ckpatel Avatar asked Sep 20 '12 07:09

ckpatel


People also ask

How to set alarms for each day of the week?

First of all yes you can use mulltiple id's to set alarms for each day separately. Then you can add alarmCalendar.set (Calendar.DAY_OF_WEEK, week); line to your existing code. Based on the week day ( from 1-7) it repeats for that day.

Is it possible to schedule a repeating alarm with alarmmanager?

You could schedule daily repeating alarm at specific time with AlarmManager, but WorkManager does offer a few extra benefit. Ability to set constraints: like only run when network is available, or don’t run when battery is low. Ensures task execution, even if the app or device restarts. Refer this.

Why is my repeat alarm not working on my Android?

Android Repeat Alarm Do Not Work Error. When you use repeat alarm, you may encounter the do not work error, this is because the interval time is too short or too long. Your alarm works properly indeed, but you can not see the effect.

What is alarmmanager RTC_wakeup in Android?

AlarmManager.RTC_WAKEUP: Similar to AlarmManager.RTC, the difference is this alarm is running even android os sleep, it will wake up the android device when the alarm run time is coming. 3. Android Repeat Alarm Do Not Work Error.


1 Answers

please try this code. is successfully run in my apps

if (chk_monday.isChecked()) {
                        forday(2);
                    } else if (chk_tuesday.isChecked()) {
                        forday(3);
                    } else if (chk_wednesday.isChecked()) {
                        forday(4);
                    } else if (chk_thursday.isChecked()) {
                        forday(5);
                    } else if (chk_friday.isChecked()) {
                        forday(6);
                    } else if (chk_sat.isChecked()) {
                        forday(7);
                    } else if (chk_sunday.isChecked()) {
                        forday(1);
                    }

public void forday(int week) {

        calSet.set(Calendar.DAY_OF_WEEK, week);
        calSet.set(Calendar.HOUR_OF_DAY, hour);
        calSet.set(Calendar.MINUTE, minuts);
        calSet.set(Calendar.SECOND, 0);
        calSet.set(Calendar.MILLISECOND, 0);

        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                calSet.getTimeInMillis(), 1 * 60 * 60 * 1000, pendingIntent);
    }
like image 65
ckpatel Avatar answered Nov 06 '22 10:11

ckpatel