Create a new Event in Android Calendar
Need a permission
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
private void createEvent(String eventName,String eventDescription,Date startDate,int totalHoursDuration,Date repeatUtil){ ContentResolver cr = getActivity().getContentResolver(); ContentValues values = new ContentValues(); values.put(CalendarContract.Events.DTSTART,""+startDate.getTime()); values.put(CalendarContract.Events.TITLE,eventName); values.put(CalendarContract.Events.DESCRIPTION,eventDescription); TimeZone timeZone = TimeZone.getDefault(); values.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID()); values.put(CalendarContract.Events.CALENDAR_ID, 1); if(repeatUtil != null){ String UntilDate = new SimpleDateFormat("yyyymmdd").format(repeatUtil.getTime()); values.put(CalendarContract.Events.RRULE, "FREQ=DAILY;UNTIL="+UntilDate); } values.put(CalendarContract.Events.DURATION, "+P"+totalHoursDuration+"H"); values.put(CalendarContract.Events.HAS_ALARM, 1); cr.insert(CalendarContract.Events.CONTENT_URI, values); }
Need a permission
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
No comments:
Post a Comment