How to using intents to view calendar data?

浪子不回头ぞ 提交于 2019-12-28 06:39:05

问题


I made this code:

long eventID = 208;
Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
Intent intent = new Intent(Intent.ACTION_VIEW)
   .setData(uri);
startActivity(intent);

I made sure the EventID was correct, and the event-title showed in the view was correct.

THE PROBLEM is the event time was incorrect, like: 1970-1-1 8:00.

Why? Anyone can Help? Thanks.


回答1:


You have to add the event begin & end time to intent's extra data :

intent.putExtra("beginTime", beginMilliTS);
intent.putExtra("endTime", endMilliTS);

I got this working by using the values from "begin" and "end" field of an event instance. This should work too with "dtstart" and "dtend" field from an event.




回答2:


This may help you!!! http://developer.android.com/guide/topics/providers/calendar-provider.html




回答3:


on Android 4.2.2, seems still having the same problem. Is it the correct behavior, or some thing missing here?

  1. got the event id through Instances.query(Globals.sContext.getContentResolver(), proj, begin, end); proj= String[]{Instances.EVENT_ID, Instances.BEGIN, Instances.END...};

  2. use the even id to view the event in calendar app.

tried with code (from http://developer.android.com/guide/topics/providers/calendar-provider.html), it still shows December 31 1969 on the 'Detail view' opened by the 'intent'; and shows current date in the 'Edit event' form if clicking on the the event on the 'Detail view' of the calendar.

...

Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);

Intent intent = new Intent(Intent.ACTION_VIEW)

   .setData(uri);

startActivity(intent);

and still does not work even with the:

intent.putExtra("beginTime", from);
intent.putExtra("endTime", till);  //'from', 'till' is the mills got from the Instances.BEGIN/END fields from the query

EDIT: the following code works. only difference is using the define CalendarContract.EXTRA_EVENT_BEGIN_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);


来源:https://stackoverflow.com/questions/9798997/how-to-using-intents-to-view-calendar-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!