Reminder Functionality

核能气质少年 提交于 2019-12-01 01:10:59

I found answer after goggling as, we can set reminder in android device by accessing default using EVENTS and Reminder.

The code is as shown:

public void addReminder(int statrYear, int startMonth, int startDay, int startHour, int startMinut, int endYear, int endMonth, int endDay, int endHour, int endMinuts){ 
    Calendar beginTime = Calendar.getInstance();
    beginTime.set(statrYear, startMonth, startDay, startHour, startMinut);
    long startMillis = beginTime.getTimeInMillis();

    Calendar endTime = Calendar.getInstance();
    endTime.set(endYear, endMonth, endDay, endHour, endMinuts);
    long endMillis = endTime.getTimeInMillis();

    String eventUriString = "content://com.android.calendar/events";
    ContentValues eventValues = new ContentValues();

    eventValues.put(Events.CALENDAR_ID, 1);
    eventValues.put(Events.TITLE, "OCS");
    eventValues.put(Events.DESCRIPTION, "Clinic App");
    eventValues.put(Events.EVENT_TIMEZONE, "Nasik");
    eventValues.put(Events.DTSTART, startMillis);
    eventValues.put(Events.DTEND, endMillis);

    //eventValues.put(Events.RRULE, "FREQ=DAILY;COUNT=2;UNTIL="+endMillis);
    eventValues.put("eventStatus", 1);
    eventValues.put("visibility", 3);
    eventValues.put("transparency", 0); 
    eventValues.put(Events.HAS_ALARM, 1);

    Uri eventUri = getContentResolver().insert(Uri.parse(eventUriString), eventValues);
    long eventID = Long.parseLong(eventUri.getLastPathSegment());

    /***************** Event: Reminder(with alert) Adding reminder to event *******************/

    String reminderUriString = "content://com.android.calendar/reminders";

    ContentValues reminderValues = new ContentValues();

    reminderValues.put("event_id", eventID);
    reminderValues.put("minutes", 1);
    reminderValues.put("method", 1);

    Uri reminderUri = getContentResolver().insert(Uri.parse(reminderUriString), reminderValues);
}   

Hope this answer helps to set reminder in calendar to all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!