How to programmatically populate Reminders section on Android device's Calendar app?
Asked Answered
A

1

7

I need to open Android device's Calendar app with some pre-populated data. The logic that Iam using seems to populate fields like:

  1. Event description
  2. Event location
  3. From Date, To Date
  4. All day event/not
  5. Repeat /Recurrence Info

I am not able to populate "Reminders" section, I would like to populate Reminders section. It will great to get some help on this

Here is the code that I am using to open Calendar app and populate date.

// Intent to open Calendar Event
Intent intent = new Intent(Intent.ACTION_INSERT)
                .setData(Events.CONTENT_URI);
intent.putExtra(Events.DESCRIPTION, desc);
intent.putExtra(Events.EVENT_LOCATION, location);
intent.putExtra(Events.TITLE, summary);
intent.putExtra(Events.EVENT_TIMEZONE, beginTime.getTimeZone().getID());
intent.putExtra(Events.STATUS, statusStr);
intent.putExtra(Events.VISIBLE, transparency);
intent.putExtra(Events.RRULE, "FREQ=YEARLY;INTERVAL=1;BYYEARDAY=1,2;UNTIL=20161210;");
intent.putExtra(Events.EXDATE, androidExDateStr.toString());

// Not sure on how to use CalendarContract.Reminders, Tried the following but does not seem to be working
intent.putExtra(CalendarContract.Reminders.DESCRIPTION, desc);
intent.putExtra(CalendarContract.Reminders.EVENT_LOCATION, location);
intent.putExtra(CalendarContract.Reminders.TITLE, summary);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis());
intent.putExtra(CalendarContract.Reminders.DTSTART, beginTime.getTimeInMillis());
intent.putExtra(CalendarContract.Reminders.EVENT_TIMEZONE, beginTime.getTimeZone().getID());
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis());
intent.putExtra(CalendarContract.Reminders.DTEND, endTime.getTimeInMillis());
intent.putExtra(CalendarContract.Reminders.STATUS, statusStr);

intent.putExtra(CalendarContract.Reminders.RRULE,"FREQ=YEARLY;INTERVAL=1;BYYEARDAY=1,2;UNTIL=20161210;");
intent.putExtra(CalendarContract.Reminders.EXDATE, androidExDateStr.toString());

//intent.putExtra(CalendarContract.Reminders.METHOD, Reminders.METHOD_EMAIL);
//intent.putExtra(CalendarContract.Reminders.MINUTES, reminderVal) ;

//intent.putExtra(CalendarContract.Events.HAS_ALARM, 1);
//} 

try {
    context.startActivity(intent);
} catch(Exception e) {
    e.printStackTrace();
    Log.v(LOG_TAG, "Cannot schedule Calendar event as specified ");

    return false;
}
Acromion answered 12/2, 2014 at 18:38 Comment(0)
R
0

Did you check the example from http://developer.android.com/guide/topics/providers/calendar-provider.html#reminders?

long eventID = 221;
...
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Reminders.MINUTES, 15);
values.put(Reminders.EVENT_ID, eventID);
values.put(Reminders.METHOD, Reminders.METHOD_ALERT);
Uri uri = cr.insert(Reminders.CONTENT_URI, values);
Rainstorm answered 3/3, 2015 at 19:5 Comment(1)
This example uses a different approach where your app directly writes data to the calendar. The OP uses a different approach, where his app opens the calendar app with prepopulated data which can be used to create calendar event.Fanion

© 2022 - 2024 — McMap. All rights reserved.