4

Is it possible to open creating reminder using intent like an event? I couldn't find any solution.

Intent intent = new Intent(Intent.ACTION_INSERT)
        .setData(CalendarContract.Events.CONTENT_URI);
startActivity(intent);

I want to invoke this:

Teivaz
  • 5,462
  • 4
  • 37
  • 75
Martin
  • 69
  • 3
  • 6
  • 3
    Possible duplicate: http://stackoverflow.com/questions/8664670/how-to-launch-alarm-clock-screen-using-intent-in-android – Nathanael Apr 29 '16 at 16:15
  • I think he means more like a calendar entry. – Gabe Sechan Apr 29 '16 at 16:17
  • @Nathanael I don't want to make an alarm, that is why I posted image. If you open google calendar, you can add event, reminder and the newest feature is goal. I want to invoke new reminder. Probably it is not possible, but I wanted to be sure I did not miss anything in documentation. – Martin Apr 30 '16 at 11:08
  • 1
    did you find a solution to add or set default minutes for reminder using intent? – user924 Apr 09 '20 at 11:59

1 Answers1

1

You can implement it like this. All you need to do is, call this method, and it will take care of the rest.

public static void pushAppointmentsToCalender(Activity curActivity, 
                                              String title, long startDate) {

    Intent intent = new Intent(Intent.ACTION_EDIT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra("beginTime", startDate);
    intent.putExtra("allDay", true);
    intent.putExtra("endTime", startTime+24*60*60*1000);
    intent.putExtra(CalendarContract.Events.TITLE, title);
    curActivity.startActivity(intent);
}

But before that, make sure you have these permissions manifested.

<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

If you are using Android API 23 (6.0) or above, I recommend you to read about the new permission model in API 23 here. And make sure to request in runtime, which will be good for your app to support future versions of android.

UPDATE

You should try this as suggested by Sanjeev Kumar in here

 /** Adds Events and Reminders in Calendar. */
 private void addReminderInCalendar() {
     Calendar cal = Calendar.getInstance();
     Uri EVENTS_URI = Uri.parse(getCalendarUriBase(true) + "events");
     ContentResolver cr = getContentResolver();
     TimeZone timeZone = TimeZone.getDefault();
 
     /** Inserting an event in calendar. */
     ContentValues values = new ContentValues();
     values.put(CalendarContract.Events.CALENDAR_ID, 1);
     values.put(CalendarContract.Events.TITLE, "Sanjeev Reminder 01");
     values.put(CalendarContract.Events.DESCRIPTION, "A test Reminder.");
     values.put(CalendarContract.Events.ALL_DAY, 0);
     // event starts at 11 minutes from now
     values.put(CalendarContract.Events.DTSTART, cal.getTimeInMillis() + 1 * 60 * 1000);
     // ends 60 minutes from now
     values.put(CalendarContract.Events.DTEND, cal.getTimeInMillis() + 2 * 60 * 1000);
     values.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());
     values.put(CalendarContract.Events.HAS_ALARM, 1);
     Uri event = cr.insert(EVENTS_URI, values);
 
     // Display event id.
     Toast.makeText(getApplicationContext(), "Event added :: ID :: " + event.getLastPathSegment(), Toast.LENGTH_SHORT).show();
 
     /** Adding reminder for event added. */
     Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(true) + "reminders");
     values = new ContentValues();
     values.put(CalendarContract.Reminders.EVENT_ID, Long.parseLong(event.getLastPathSegment()));
     values.put(CalendarContract.Reminders.METHOD, Reminders.METHOD_ALERT);
     values.put(CalendarContract.Reminders.MINUTES, 10);
     cr.insert(REMINDERS_URI, values);
 }
 
 /** Returns Calendar Base URI, supports both new and old OS. */
 private String getCalendarUriBase(boolean eventUri) {
     Uri calendarURI = null;
     try {
         if (android.os.Build.VERSION.SDK_INT <= 7) {
             calendarURI = (eventUri) ? Uri.parse("content://calendar/") :
             Uri.parse("content://calendar/calendars");
         } else {
             calendarURI = (eventUri) ? Uri.parse("content://com.android.calendar/") : Uri
                     .parse("content://com.android.calendar/calendars");
         }
     } catch (Exception e) {
         e.printStackTrace();
     }
     return calendarURI.toString();
 }
Community
  • 1
  • 1
Sibidharan
  • 2,717
  • 2
  • 26
  • 54
  • Oh remainders, will change accordingly – Sibidharan Apr 30 '16 at 13:29
  • 1
    I appreciate, you are trying to help, but there is no problem of making a event and reminder for this event, I want to invoke reminder, like when you use Google now, or you just add reminder in Google calendar. Probably it's not possible, at least for now. – Martin May 04 '16 at 17:03