如何使用 Intent (Froyo) 启动 Android 日历应用程序
我想从 Android 应用程序打开日历应用程序。当我在线搜索时,我得到的只是使用意图创建新事件。我可以找到打开联系人和图库等的意图。
是否可以将日历启动到特定的一周或一天?如果可能的话,有人可以帮我吗?
I want to open up the Calendar application from an android application. When i searched online, all i got is to create new events using intent. I could find Intents to open Contacts and Gallery etc.
Is it possible to launch the Calendar to a specific week or day? If possible, could someone please help me with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以通过两种方式打开日历视图:
1) 按特定日期
2) 按特定事件
为此,您必须添加以下两个权限
1) 按特定日期:
2) 按特定事件:
注意:
CalendarContract
内容提供程序已添加到 API 级别 14 的 Android SDK 中。更多信息,您可以访问此链接You can open Calendar View by two means:
1) by particular date
2) by particular event
For this you have to add following two permissions
1) by particular date:
2) by particular event:
Note:
CalendarContract
content provider was added to the Android SDK in API Level 14. For more information you can visit this link查看Android源代码中的日历应用程序后,您只能直接调用AgendaActivity。其他的将不起作用。正如其他发帖者所指出的,您可以直接与光标交互来读取/创建事件,但您无法将日历应用程序调用到 AgendaView 之外的视图。原因是开发人员通过使用以下活动定义在 Cal 应用程序的清单中限制了该功能:
请注意,只有 AgendaActivity 具有 android:exported="true"。如果您尝试调用其他活动,您将收到权限异常。
但是,您可以使用以下代码将 AgendaActivity 调用到任意一天:
After reviewing the Calendar App in the Android source code you can only invoke the AgendaActivity directly. The others will not work. As the other posters have noted you can interact directly with the cursor to read/create events, but you can't invoke the calendar app to a view other than the AgendaView. The reason is that the developers have limited that ability in the manifest for the Cal app by using the following activity definitions:
Note that only the AgendaActivity has android:exported="true". If you attempt to call the other activities you will get a permission exception.
However, you can invoke the AgendaActivity to an arbitrary day with the following code:
使用 Intent 查看日历数据
Calender Provider 提供了两种不同的方式来使用 VIEW Intent:
将权限添加到清单
下面是一个示例,展示了如何打开特定日期的日历:
下面是一个示例,展示了如何打开特定日期的事件查看:
是否可以启动特定周或某一天的日历?
因此,现在可以,但需要
最低 API 14
。有关更多详细信息,请访问 http://developer.android.com/guide /topics/providers/calendar-provider.html#intents
Using intents to view calendar data
Calender Provider offers two different ways to use the VIEW Intent:
add permissions to manifest
Here is an example that shows how to open the Calendar to a particular date:
Here is an example that shows how to open an event for viewing:
Is it possible to launch the Calendar to a specific week or day?
So, now it is possible, but requires
min API 14
.For more details visit http://developer.android.com/guide/topics/providers/calendar-provider.html#intents
AgendaActivity 加载“议程”视图。
根据我的经验,您无法深入链接到 Android 中的日、周和月活动,但是您可以使用“LaunchActivity”来加载上次打开的视图。
AgendaActivity loads the "Agenda" view.
From my experience you can't deep link into the Day, Week and Month activities in stock Android, however you can use "LaunchActivity" which loads the last opened view.
您可以使用以下代码,如果您的设备上安装了多个日历应用程序,您还可以选择一个日历应用程序
You can use the below code, which also enables you to choose a calendar app if there are multiple calendar apps installed on your device
通过繁琐的实验过程,我发现:
Intent calendarIntent = new Intent() ;
calendarIntent.setClassName("com.android.calendar","com.android.calendar.AgendaActivity");
...适合我启动日历的议程活动。没有
尝试过,但也许是 com.android.calendar.DayActivity,
.WeekActivity,和.MonthActivity会启动相应的
活动。
By a process of tedious experimentation, I've found that:
Intent calendarIntent = new Intent() ;
calendarIntent.setClassName("com.android.calendar","com.android.calendar.AgendaActivity");
...works for me to launch the Calendar's Agenda Activity. Haven't
tried, but perhaps com.android.calendar.DayActivity,
.WeekActivity,and .MonthActivity will launch the corresponding
Activities.