简体   繁体   English

android在android 4.0中添加日历事件崩溃

[英]android adding calendar events crashes in android 4.0

Following is the code which i am using to add events in my android app 以下是我用于在我的Android应用程序中添加事件的代码

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(Events.TITLE, summary);
intent.putExtra(Events.DESCRIPTION, summary);
intent.putExtra(Events.EVENT_LOCATION, "");     
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginCal.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endCal.getTimeInMillis());
intent.putExtra(Events.ALL_DAY, allDayFlag);
intent.putExtra(Events.STATUS, 1);
intent.putExtra(Events.VISIBLE, 0);
intent.putExtra(Events.HAS_ALARM, 1);
startActivity(intent);

This code works good in android 4.0 emulator but when i checked in Samsung Galaxy S II of andriod 4.0 it gets crashed and the error log seems to be as follows 这个代码在Android 4.0模拟器中工作得很好但是当我在三星Galaxy S II中检查了andriod 4.0时它会崩溃并且错误日志似乎如下

Error ( 4489): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT typ=vnd.android.cursor.item/event (has extras) }

how to rectify this error 如何纠正这个错误

请尝试using Intent.ACTION_EDIT

I tried in the following way and its working fine 我尝试了以下方式,并且工作正常

ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startTime);
values.put(Events.DTEND, endTime);
values.put(Events.TITLE, summary);
values.put(Events.DESCRIPTION, summary);
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "America/Los_Angeles");
values.put(Events.EVENT_LOCATION, "");  
values.put(Events.ALL_DAY, allDayFlag);
values.put(Events.STATUS, 1);
values.put(Events.HAS_ALARM, 1);
Uri uri = cr.insert(Events.CONTENT_URI, values);

there might not be any calendar configured in your calendar application. 您的日历应用程序中可能没有配置任何日历。 try creating an event in native calendar app which was shipped with device. 尝试在设备随附的本机日历应用中创建活动。 if that generate any error while creating an event. 如果在创建事件时生成任何错误。

if yes , absence of configured calendar might be the issue. 如果 ,则缺少配置的日历可能是问题。

if no , that is if you could successfully create an event in you native app then probably there is a problem in your code. 如果不是 ,那就是如果你可以在你的本机应用程序中成功创建一个事件,那么你的代码中可能存在问题。

But one thing i noticed in your code is that you have not specified calendar_id, this event supposed to be created in. 但是我在你的代码中注意到的一件事是你没有指定calendar_id,这个事件应该是在创建的。

Calendar_id is mandatory field while creating an event in calendar. 在日历中创建事件时,Calendar_id是必填字段。 try putting this thing in your code. 尝试将这个东西放在你的代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM