将事件添加到Outlook日历

时间:2018-12-26 15:10:04

标签: android events outlook calendar

下面是我的代码,用于添加日历帐户,然后将事件添加到该日历,

div.header__font:hover {
    animation: 0.5s ease-out 0s  forwards highlight;
}

日历方法:

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);
}

问题是,该事件未添加到所需的日历中。我也没有任何错误。这里需要任何更正吗?

1 个答案:

答案 0 :(得分:1)

您可以在事件中添加“ CALENDAR_ID”参数,例如:

values.put(CalendarContract.Events。CALENDAR_ID,“”);

有关更多信息,请参考此链接:

CalendarContract.Events