Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create or add a non-editable event to a user's calendar in Android?

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, "[email protected]");

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, "[email protected]");

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.

like image 366
s-hunter Avatar asked Feb 23 '18 19:02

s-hunter


People also ask

How do I allow others to edit Google Calendar events?

Settings and sharing.Under “Share with specific people,” click Add people. Add a person's or Google group's email address. Use the drop-down menu to adjust their permission settings. Learn more about access permissions.

How do I add an event to someone else's Google Calendar?

Use a link to add a public calendar On your computer, open Google Calendar. From URL. Enter the calendar's address. Click Add calendar.


1 Answers

when you authenticate to a users google calendar account you are logged in as the user. when you create an event the its as the user themselves creates the event and they are then the owner of the event. You cant create an event with someone else as the owner.

What you should consider doing is adding events to your own calendar and inviting these people to the event then they can choose to add the event to their calendar themselves. They will be guests of your event and not owner and then will be unable to edit the event.

You can try and update the event after you have created it and add yourself as an owner and update the users setting them as guest. However i am not sure this its possible to set someone as a guest on an event in their personal calendar.

like image 54
DaImTo Avatar answered Sep 17 '22 10:09

DaImTo