-
-
Save anonymous/d2c4db45e8bbe20e1c36c6da78382d9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long calId = System.currentTimeMillis(); | |
CalendarEvent calendarEvent = new CalendarEvent(); | |
calendarEvent.setTitle(eventName); | |
calendarEvent.setDescr(eventDescription); | |
calendarEvent.setLocation(venue); | |
calendarEvent.setStartTime(receivedStartMilliSeconds); | |
calendarEvent.setEndTime(receivedEndMilliSeconds); | |
calendarEvent.setEventTimezone(TimeZone.getDefault().getID()); | |
calendarEvent.setIdCalendar(calId); | |
//its function | |
addEvent(calendarEvent); | |
public void addEvent(CalendarEvent evt) { | |
try { | |
ContentResolver cr = ctx.getContentResolver(); | |
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) { | |
return; | |
} | |
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, CalendarEvent.toICSContentValues(evt)); | |
Util.showToastMessage(activity, getResources().getString(R.string.str_event_added_in_your_calendar)); | |
Uri evtUri = ctx.getContentResolver().insert(getCalendarUri("events"), | |
CalendarEvent.toContentValues(evt)); | |
Log.d("Info", "" + evtUri); | |
}catch (Exception e){ | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment