Android的日历经常性活动有错误的结束日期/时间经常性、有错误、日历、日期

2023-09-06 23:29:39 作者:独语

这是我的code查看( 事件是一个包含所有这些事件的ArrayList)从ListActivity选择一个事件:

This is my code to view an event selected from a ListActivity (events is the ArrayList containing all those events):

Uri viewUri = Uri.parse("content://com.android.calendar/events/" + events.get(position).id);
Intent l_intent = new Intent(Intent.ACTION_VIEW);
l_intent.putExtra("beginTime", Long.parseLong(events.get(position).startTime));
l_intent.putExtra("endTime", Long.parseLong(events.get(position).endTime));
startActivity(l_intent);

这code完全适用于除经常性事件的所有事件。对于被反复出现任何情况下,endTime的返回为空,导致程序崩溃。任何人都知道如何解决这个问题?是否有其他附加功能我要传递?

This code works perfectly for all events except recurring events. For any event that is recurring, endTime returns as null, causing the program to crash. Anyone know how to get around this? Are there other extras I should be passing?

推荐答案

BEGINTIME和endTime可以是0 / null,因为你从一个错误的数据库得到了他们,从事件的数据库肯定。 您应该使用的实例的数据库,而不是。(例如:在SDK 8:内容//com.android.calendar/instances/when/)

beginTime and endTime can be 0/null because you got them from a wrong database, certainly from events database. You should use the instances database instead (ex: "content://com.android.calendar/instances/when/" on SDK 8).

在实例的DB,你会得到所有真正的事件:有,每个重复事件有根据需要尽可能多的情况下,正确的开始和结束时间戳记;和其他事件是可见的了。你只需要阅读这些领域 - EVENT_ID,开始,结束 - 。并用它们来打开你的意图

In the instances DB, you'll get all "real" events : There, each recurring event has as many instances as needed, with correct begin and end timestamps; and the other events are visible too. You only have to read these fields - event_id, begin, end - and use them to open your Intent.