I've looked these links for adding an event to a google calendar in Android, and I am able to add events but how can I make the event not editable by the user?
How to add calendar events in Android?
https://developer.android.com/guide/topics/providers/calendar-provider.html#add-event
The code for adding an event.
String eventTitle = "Jazzercise";
long calID = 3;
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2018, 2, 18, 6, 00);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2018, 2, 18, 8, 00);
endMillis = endTime.getTimeInMillis();
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, startMillis);
values.put(CalendarContract.Events.DTEND, endMillis);
values.put(CalendarContract.Events.TITLE, "Jazzercise");
values.put(CalendarContract.Events.DESCRIPTION, "Group workout");
values.put(CalendarContract.Events.CALENDAR_ID, calID);
values.put(CalendarContract.Events.EVENT_TIMEZONE, "America/Los_Angeles");
values.put(CalendarContract.Events.ORGANIZER, "google_calendar@gmail.com");
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED) {
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
long eventID = Long.parseLong(uri.getLastPathSegment());
Log.i("Calendar", "Event Created, the event id is: " + eventID);
Snackbar.make(view, "Jazzercise event added!", Snackbar.LENGTH_SHORT).show();
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_CALENDAR}, MY_PERMISSIONS_REQUEST_WRITE_CALENDAR);
}
This line in the above code will actually make the event not editable by the user for a brief moment after the event has been created, after that user will be able to edit the event.
values.put(CalendarContract.Events.ORGANIZER, "google_calendar@gmail.com");
For example, after I booked a flight with google flight, an event of this flight will be added to my google calendar automatically but I can't edit the event details such as event name, time, etc. I can only delete it if I want to. So, it is obvious that's possible to create/add an event to a user's google calendar, but I just don't know how to do that. Does anyone know how to do this?
Plus the user should not have the option to accept or decline the event. The only option is to delete it after it is being added to the user's calendar.