【问题标题】:Android - insert calendar eventAndroid - 插入日历事件
【发布时间】:2016-12-01 14:53:34
【问题描述】:

我尝试将新活动插入谷歌日历。我的代码如下所示:

@OnClick(R.id.add_event_button)
    public void addEvent() {
        CalendarDB calendar = (CalendarDB) mCalendarSpinner.getSelectedItem();
        String id = calendar.calendarId;
        ContentValues event = new ContentValues();
        event.put(CalendarContract.Events.EVENT_TIMEZONE, "Europe/Berlin");  // Here choose your location time zone

        event.put("calendar_id", id);
        event.put("title", "barteq calendar tutorial test");
        event.put("description", "This is a simple test for calendar api");
        event.put("dtstart", System.currentTimeMillis());
        event.put("dtend", System.currentTimeMillis() + 1800*1000);
        event.put("allDay", 0);
        event.put("eventStatus", 3);

        event.put("hasAlarm", 1);
        Uri l_eventUri;
        if (Build.VERSION.SDK_INT >= 8 ) {
            l_eventUri = Uri.parse("content://com.android.calendar/events");
        } else {
            l_eventUri = Uri.parse("content://calendar/events");
        }
        Uri l_uri = this.getContentResolver().insert(l_eventUri, event);
        }

但是我遇到了 id 问题:

 java.lang.IllegalArgumentException: New events must specify a calendar id

我已经检查过了 - 我正在发送正确的 id - 例如 xxxx@google.pl 那么为什么 google 有问题呢?有任何想法吗 ?提前致谢

【问题讨论】:

    标签: java android google-api google-calendar-api


    【解决方案1】:

    添加此列指定日历ID

    event.put(CalendarContract.Events.CALENDAR_ID,1);
    

    【讨论】:

    • 问题依旧存在:/
    猜你喜欢
    • 2012-01-31
    • 1970-01-01
    • 2012-10-10
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多