gpt4 book ai didi

android - 日历提供程序批量插入

转载 作者:太空狗 更新时间:2023-10-29 13:32:47 24 4
gpt4 key购买 nike

您好,我正在尝试使用 Calendar Provider 插入几个日历事件通过批量插入。我的代码因 IllegalArgumentException 而失败

 private void synchronizeCalendar(long calID){
TLApplication.getDB().getDB().beginTransaction();
try {
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
TLCalendar calendar = TLApplication.getDB().loadCalendar();
if(calendar.days!=null && calendar.days.size()> 0){
for (TLDay day : calendar.days) {
for (TLEvent event : day.events) {
List<TLComponent> comps = TLApplication.getDB().loadComponents(event.cid);
if(comps.size()>0){
TLComponent comp = comps.get(0);
//new batch operation
ops.add(ContentProviderOperation.newInsert(getCalendarUri())
.withValue(Events.DTSTART, getStartDate(event, comp)) //long
.withValue(Events.DTEND, getEndDate(event, comp)) //long
.withValue(Events.TITLE, getTitle(event)) //String
.withValue(Events.EVENT_LOCATION, getLocation(event)) //String
.withValue(Events.DESCRIPTION, getNotes(comp)) //String
.withValue(Events.CALENDAR_ID, calID) //long
.withValue(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID()) //String
.build());
}
}
}
if(ops.size() > 0){
ContentResolver cr = ctx.getContentResolver();
ContentProviderResult[] results = cr.applyBatch(CalendarContract.AUTHORITY, ops);
for (ContentProviderResult result : results) {
Log.v(TAG, "addBatchEvent: " + result.uri.toString());
}
}else{
Log.w(TAG, "No batch operations found! Do nothing");
}
}

}catch (Exception e) {
Log.e(TAG, "synchronizeCalendar", e);

} finally{
TLApplication.getDB().getDB().endTransaction();
}
}

异常(exception)是:java.lang.IllegalArgumentException: column 'calendar_id' 无效

此代码的模式是来自 sdk 的“ContactManager”示例:docs/resources/samples/ContactManager/src/com/example/android/contactmanager/ContactAdder.html

有没有人有批量插入日历的经验?我需要实现 Sync Adapter 吗?

最佳答案

在我的实现中发现了错误。我已使用 getCalendarUri() 获取 Calendars.CONTENT_URI,但我必须为事件使用 Events.CONTENT_URI

关于android - 日历提供程序批量插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13719332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com