插入事件中使用的意图日历 [英] insert event to calendar using intent

查看:101
本文介绍了插入事件中使用的意图日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这已被要求previously在这个论坛上,但我想这里的一切都写,仍然没有为我工作。我想要做的是插入一个事件日历。因为有我的设备上多个日历应用程序,我想使用户能够选择哪个日历应用程序应包含新事件,类似于当用户试图使用地图应用程序来查看的位置发生什么情况(用户可以选择是否激活谷歌地图,互联网......)。出于这个原因,我必须使用意向。

I know this has been asked previously in this forum, but I tried everything written here and still nothing works for me. What I want to do is to insert an event to the calendar. Since there are several calendar applications on my device, I want to enable the user to choose which calendar application should contain the new event, similar to what happens when the user attempts to view a location using a map application (the user can select whether to activate google maps, the internet, ...). For this reason, I have to use an Intent.

顺便说一句,我知道,插入新的事件来使用意图日历只允许与SDK版本14或更高版本的设备。我器件具有15的API级别,所以它支持日历API。

BTW, I'm aware that inserting new events to the calendar using Intents is allowed only on devices with SDK version 14 or higher. My device has an API level of 15, so it supports the calendar API.

下面是我的code:

Intent calendarIntent = new Intent(Intent.ACTION_INSERT);
calendarIntent.setData(Events.CONTENT_URI);
calendarIntent.putExtra(Events.TITLE, "title");
calendarIntent.putExtra(Events.EVENT_LOCATION, "address");
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.YEAR, 2013);
cal.set(Calendar.HOUR_OF_DAY, 20);
cal.set(Calendar.MINUTE, 0);
calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, cal.getTime().getTime());
cal.set(Calendar.HOUR_OF_DAY, 20);
cal.set(Calendar.MINUTE, 30);
calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, cal.getTime().getTime());
ctx.startActivity(calendarIntent);

我得到这个异​​常:

I get this exception:

02-04 17:55:23.957: E/AndroidRuntime(3781): FATAL EXCEPTION: main
02-04 17:55:23.957: E/AndroidRuntime(3781): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.applicat.meuchedet/com.applicat.meuchedet.MainScreenActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT dat=content://com.android.calendar/events (has extras) }
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.os.Looper.loop(Looper.java:137)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.ActivityThread.main(ActivityThread.java:4507)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at java.lang.reflect.Method.invokeNative(Native Method)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at java.lang.reflect.Method.invoke(Method.java:511)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at dalvik.system.NativeStart.main(Native Method)
02-04 17:55:23.957: E/AndroidRuntime(3781): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT dat=content://com.android.calendar/events (has extras) }
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1535)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1387)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.Activity.startActivityForResult(Activity.java:3190)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at com.applicat.meuchedet.Screen.startActivity(Screen.java:433)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at com.applicat.meuchedet.CalendarAppointmentScheduler.writeAppointmentToCalendar(CalendarAppointmentScheduler.java:137)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at com.applicat.meuchedet.MainScreenActivity.onCreate(MainScreenActivity.java:258)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.Activity.performCreate(Activity.java:4465)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
02-04 17:55:23.957: E/AndroidRuntime(3781):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
02-04 17:55:23.957: E/AndroidRuntime(3781):     ... 11 more

我在做什么错了?

What am I doing wrong?

感谢名单

推荐答案

您抓住ActivityNotFoundException因为任何活动无法处理你的行动。

You caught ActivityNotFoundException because any activity can't handle your action.

而不是使用 Intent.ACTION_INSERT 试着这样做:

Instead using Intent.ACTION_INSERT try to do like this :

Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(Events.TITLE, strTitle);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                    startDateMillis);
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                    endDateMillis);
intent.putExtra(Events.ALL_DAY, false);// periodicity
            intent.putExtra(Events.DESCRIPTION,strDescription));

您可以检查其他属性的开发者文档中

You can check in developer documentation for other attributes.

这篇关于插入事件中使用的意图日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆