2

I am working on a application which set the events and reminders in calendars. The code i used for it is as follows.

private void addReminder(int statrYear, int startMonth, int startDay, int startHour, int startMinut, String title){
    Calendar beginTime = Calendar.getInstance();
    beginTime.set(statrYear, startMonth, startDay, startHour, startMinut);
    long startMillis = beginTime.getTimeInMillis();

    // String to access default google calendar of device for Event setting.
    String eventUriString = "content://com.android.calendar/events";


    ContentValues eventValues = new ContentValues();
    eventValues.put(Events.CALENDAR_ID, 1);
    eventValues.put(Events.TITLE, title);
    eventValues.put(Events.DESCRIPTION, "Discription");
    eventValues.put(Events.EVENT_TIMEZONE, "India");
    eventValues.put(Events.DTSTART, startMillis);
    eventValues.put("eventStatus", 1);
    eventValues.put("visibility", 3);
    eventValues.put("transparency", 0);
    eventValues.put(Events.HAS_ALARM, 1);

    // Set Event in calendar.
    Uri eventUri = getContentResolver().insert(Uri.parse(eventUriString), eventValues);
    // Getting ID of event in Long.
    long eventID = Long.parseLong(eventUri.getLastPathSegment());

    /***************** Event: Reminder(with alert) Adding reminder to event *******************/
    // String to access default google calendar of device for reminder setting.
    String reminderUriString = "content://com.android.calendar/reminders";      
    ContentValues reminderValues = new ContentValues();

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

    //Setting reminder in calendar on Event.
    Uri reminderUri = getContentResolver().insert(Uri.parse(reminderUriString), reminderValues);
}

Now this code is working fine to add reminders on "Samsung Galaxy S2" and other devices except the "Sony Xperia".

I am not able to set reminders and may be due to the reason that i am not able to get calender of device. So i think that i have to fetch the default calendar id of device in my app. So that i can set reminders on every device.

Please suggest me that am i on right way or there is any other issue due to which reminder is not setting in "Sony Xperia". I tested this code on "Samsung Galaxy S2" and some of the "Samsung and LG and Sony Xperia" device.

Please suggest me what should i do.

Thank You

Manoj Fegde
  • 4,786
  • 15
  • 50
  • 95

1 Answers1

3

I think the calendar ids are assigned to calendars starting from 1. So the inbuilt default calendar if present will have id 1 or else a calendar has to be added by the user before there exists a calendar with id=1

ARK
  • 165
  • 13