alarmmanager - How to schedule alarm weekly in android ? -


i want schedule alarm according desired days e.g. sunday,tuesday,thursday. have scheduled according time not able week days.

below code:

private void startscheduler(context context) {         calendar starttimmer = calendar.getinstance();        starttimmer.settimezone(timezone.getdefault());                starttimmer.set(calendar.hour_of_day,shour);        starttimmer.set(calendar.minute,sminute);        starttimmer.set(calendar.second,00);          alarmmanager alarmmanager = (alarmmanager) getsystemservice(context.alarm_service);                 intent startalarmtime = new intent(schedule_details.this, myalaramstartreceiver.class);                 pendingintent pendingintent1 = pendingintent.getbroadcast(context, 0, startalarmtime, 0);         alarmmanager.set(alarmmanager.rtc_wakeup, starttimmer.gettimeinmillis(),pendingintent1);             log.d("<<my-start-alarm>>", "alarm set start at: " + starttimmer.gettime().tolocalestring()); } 

here answer:

public class myreceiver extends broadcastreceiver { dbadapter mdba; sqlitedatabase mdb; ringtone rt; mediaplayer mp; alertdialog.builder alertbox; context ctx;  @override public void onreceive(context context, intent intent) {      dbhelper mdbh = new dbhelper(context, null, null, 1);     mdb = mdbh.getwritabledatabase();     mdb.setlockingenabled(true);     mdba = new dbadapter(context);     mdba.open();     cursor cr = mdb.query("mreminderentry", null, null, null, null,             null, null);     if (cr.equals(null)) {         system.out.println("no data found");     } else {         date d = new date();         calendar calendar = calendar.getinstance();         int day = calendar.get(calendar.day_of_week);         string today = null;         if (day == 2) {             today = "monday";         } else if (day == 3) {             today = "tuesday";         } else if (day == 4) {             today = "wednesday";         } else if (day == 5) {             today = "thursday";         } else if (day == 6) {             today = "friday";         } else if (day == 7) {             today = "saturday";         } else if (day == 1) {             today = "sunday";         }          int system_hour = d.gethours();         int system_minute = d.getminutes();         cr.movetofirst();         (int = 0; < cr.getcount(); i++) {             if (cr.getstring(3).equals(system_hour + ":" + system_minute)                     && cr.getstring(1).equals("daily")) {                 intent scheduledintent = new intent(context, myscheduledactivity.class);                 scheduledintent.addflags(intent.flag_activity_new_task);                 context.startactivity(scheduledintent);                  break;              } else if (cr.getstring(3).equals(                     system_hour + ":" + system_minute)                     && cr.getstring(1).equals(today)) {                  intent scheduledintent = new intent(context, myscheduledactivity.class);                 scheduledintent.addflags(intent.flag_activity_new_task);                 context.startactivity(scheduledintent);                  break;             } else {                 system.out.println("no matching");             }             cr.movetonext();         }     }     cr.close();     mdba.close(); } 

}


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -