Android 如何使用意图查看日历数据?

Android 如何使用意图查看日历数据?,android,android-intent,calendar,Android,Android Intent,Calendar,我制定了以下代码: long eventID = 208; Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID); Intent intent = new Intent(Intent.ACTION_VIEW) .setData(uri); startActivity(intent); 我确保EventID是正确的,并且视图中显示的事件标题是正确的 问题是事件时间不正确,例如:1970-1-18:00 为什么??

我制定了以下代码:

long eventID = 208;
Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
Intent intent = new Intent(Intent.ACTION_VIEW)
   .setData(uri);
startActivity(intent);
我确保EventID是正确的,并且视图中显示的事件标题是正确的

问题是事件时间不正确,例如:1970-1-18:00

为什么??有人能帮忙吗?谢谢。

这可能会对你有所帮助!!!

您必须将事件开始和结束时间添加到intent的额外数据中:

intent.putExtra("beginTime", beginMilliTS);
intent.putExtra("endTime", endMilliTS);
我通过使用事件实例的“开始”和“结束”字段中的值来实现这一点。
这也适用于事件中的“dtstart”和“dtend”字段。

在Android 4.2.2上,似乎仍然存在相同的问题。这是正确的行为,还是遗漏了什么

  • 通过Instances.query(Globals.sContext.getContentResolver(),proj,begin,end)获取事件id;proj=String[]{Instances.EVENT_ID,Instances.BEGIN,Instances.END…}

  • 使用偶数id在日历应用程序中查看事件

  • 使用代码(来自)进行了尝试,它仍然在“意图”打开的“细节视图”上显示1969年12月31日;如果单击日历“详细视图”上的事件,则在“编辑事件”窗体中显示当前日期

    即使在以下情况下仍然不起作用:

    intent.putExtra("beginTime", from);
    intent.putExtra("endTime", till);  //'from', 'till' is the mills got from the Instances.BEGIN/END fields from the query
    
    编辑: 下面的代码可以工作。唯一的区别是使用define
    CalendarContract.EXTRA\u EVENT\u BEGIN\u TIME

    Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventId);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(uri);
    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, from);
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, till);
    startActivity(intent);
    

    请尝试查询日历数据库,这可能会让您了解为什么会有这样的情况。请尝试查询,但时间数据是正确的。您能否发布如何读取日历内容的代码?太长了。下面的代码如下:1,查询数据库,获取eventID。第二,使用API(前面的代码)打开intent,但是intent视图显示了错误的事件时间。但是,当试图查看重复发生的事件时,此代码似乎会崩溃。你知道有什么办法吗?从来没见过撞车。要编辑录制事件,必须获取与之关联的真实事件。使用实例数据库,而不是事件数据库;然后使用事件id begin和end(这是实例数据库中字段的名称)来设置意图。非常感谢。如果你愿意,在这里提交你的答案,我会接受:很好。这也解决了我在试图查看事件细节时在HTC Sense上冻结应用程序的问题。谢谢
    Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventId);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(uri);
    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, from);
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, till);
    startActivity(intent);