将事件添加到Outlook日历 [英] Adding Event to Outlook Calendar

查看:288
本文介绍了将事件添加到Outlook日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Below is my code to Add calendar Account and then adding Event to that calendar,

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

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

The problem is, the event is not getting added to the desired Calendar. I'm not getting any error too. Any correction needed here?

推荐答案

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

You could add " CALENDAR_ID " parameter to the Events, For example:

values.put(CalendarContract.Events.CALENDAR_ID,");

values.put(CalendarContract.Events. CALENDAR_ID, "");

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

For more information, please refer to this link:

CalendarContract.Events

这篇关于将事件添加到Outlook日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆