Ниже приведен мой код для добавления учетной записи календаря и последующего добавления события в этот календарь,
AuthenticationManager.getInstance().setContextActivity(this);
AuthenticationManager.getInstance().connect(
new AuthenticationCallback<AuthenticationResult>() {
@Override
public void onSuccess(AuthenticationResult result) {
Log.i(TAG, "onConnectButtonClick - Successfully connected to Office 365");
String type = result.getUserInfo().getIdentityProvider();
String accountOwner = result.getUserInfo().getDisplayableId();
addCalendar(type, accountOwner);
}
@Override
public void onError(final Exception e) {
Log.e(TAG, "onCreate - " + e.getMessage());
}
});
Метод календаря:
public void addCalendar(String type, String accountOwner) {
ContentValues contentValues = new ContentValues();
contentValues.put(CalendarContract.Calendars.ACCOUNT_NAME, accountOwner);
contentValues.put(CalendarContract.Calendars.ACCOUNT_TYPE, type);
contentValues.put(CalendarContract.Calendars.NAME, accountOwner);
contentValues.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, "Outlook");
contentValues.put(CalendarContract.Calendars.CALENDAR_COLOR, "232323");
contentValues.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_EDITOR);
contentValues.put(CalendarContract.Calendars.OWNER_ACCOUNT, accountOwner);
contentValues.put(CalendarContract.Calendars.ALLOWED_REMINDERS, "METHOD_ALERT, METHOD_EMAIL, METHOD_ALARM");
contentValues.put(CalendarContract.Calendars.ALLOWED_ATTENDEE_TYPES, "TYPE_OPTIONAL, TYPE_REQUIRED, TYPE_RESOURCE");
contentValues.put(CalendarContract.Calendars.ALLOWED_AVAILABILITY, "AVAILABILITY_BUSY, AVAILABILITY_FREE, AVAILABILITY_TENTATIVE");
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_CALENDAR}, 23);
}
Uri uri = CalendarContract.Calendars.CONTENT_URI;
uri = uri.buildUpon().appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, accountOwner)
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, type).build();
getContentResolver().insert(uri, contentValues);
}
Добавление события:
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, beginTime.getTimeInMillis());
values.put(CalendarContract.Events.DTEND, endTime.getTimeInMillis());
values.put(CalendarContract.Events.TITLE, "Tech Stores");
values.put(CalendarContract.Events.DESCRIPTION, "Successful Startups");
values.put(CalendarContract.Events.CALENDAR_ID, 10);
values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
values.put(CalendarContract.Events.EVENT_LOCATION, "London");
values.put(CalendarContract.Events.GUESTS_CAN_INVITE_OTHERS, "1");
values.put(CalendarContract.Events.GUESTS_CAN_SEE_GUESTS, "1");
values.put(CalendarContract.Events.ORGANIZER, "azhar@outlook.com");
cr.insert(CalendarContract.Events.CONTENT_URI, values);
Проблема в том, что событие не добавляется в нужный календарь.Я тоже не получаю никакой ошибки.Любая коррекция нужна здесь?