How to add calendar events in Android that will not become preliminary meetings in the exchange?

I have a small application in which one of the functions includes the current state for the user. This is shown to other users using our backend, and in some cases it is also necessary to have state synchronization with the user's calendar.

I use the ICS: s calendar API to perform this synchronization, and it works well with Google Calendar. If the user chooses to synchronize with the exchange account, however, the status elements are displayed as meeting requests with a preliminary status.

Since I have limited experience with calendars, my question is which fields should go with a calendar event, so that it appears as a regular event in the exchange, as well as the Google calendar. I insert events directly, without using intentions, because the goal is to make it easy for the user. The current code looks like this (status is my state data model).

ContentResolver cr = getContentResolver(); ContentValues values = new ContentValues(); values.put(CalendarContract.Events.DTSTART, status.StartTimeLocal.getTime()); values.put(CalendarContract.Events.DTEND, status.StopTimeLocal.getTime()); values.put(CalendarContract.Events.TITLE, status.DisplayName); values.put(CalendarContract.Events.DESCRIPTION, status.Text); values.put(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY); values.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CONFIRMED); values.put(CalendarContract.Events.GUESTS_CAN_INVITE_OTHERS, false); values.put(CalendarContract.Events.HAS_ATTENDEE_DATA, false); values.put(CalendarContract.Events.CALENDAR_ID, mCalendarId); values.put(CalendarContract.Events.EVENT_TIMEZONE, "Europe/Stockholm"); Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values); 

When I try to add a new item manually to the phone calendar, it synchronizes correctly with the exchange, so it seems possible. But from my application, it’s not easy for me to make it work.

+4
source share
1 answer

Specifying Calendars.OWNER_ACCOUNT in your ContentValues ​​should do the trick.

 ContentValues values = new ContentValues(); ... values.put(Calendars.OWNER_ACCOUNT, ACCOUNT_NAME); 

Before embedding, CONTENT_URI must include ACCOUNT_NAME and ACCOUNT_TYPE

 Uri contentUri CalendarContract.Calendars.CONTENT_URI .buildUpon() .appendQueryParameter(Calendars.ACCOUNT_NAME, ACCOUNT_NAME) .appendQueryParameter(Calendars.ACCOUNT_TYPE, "com.google") .build(); 

Now insert:

 Uri uri = cr.insert(contentUri, values); 
+2
source

Source: https://habr.com/ru/post/1411024/


All Articles