本文介绍了如何以编程方式添加周期性事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发添加事件日历应用程序。我用下面的code插入重复事件,但它的力量关闭与一个错误的应用程序java.lang.IllegalArgumentException异常:DTEND和持续时间不能同时为空的事件
i am developing an application for adding events to calendar. i am using following code to insert recurring event but it force closes the application with an error "java.lang.IllegalArgumentException: DTEND and DURATION cannot both be null for an event."
code:
ContentValues event = new ContentValues();
event.put("calendar_id", 1);
event.put("title", "Event Title");
event.put("description", "Event Desc");
event.put("eventLocation", "Event Location");
event.put("dtstart", Long.parseLong("1315432844000"));
event.put("rrule", "FREQ=WEEKLY;WKST=SU;BYDAY=WE");
event.put("allDay", 1); // 0 for false, 1 for true
event.put("eventStatus", 1);
event.put("hasAlarm", 1); // 0 for false, 1 for true
Uri url = getContentResolver().insert(eventsUri, event);
在此先感谢
推荐答案
这是我的修正code..working罚款:)
this is my corrected code..working fine :)
public class mainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Uri eventsUri;
if (android.os.Build.VERSION.SDK_INT <= 7) {
eventsUri = Uri.parse("content://calendar/events");
} else {
eventsUri = Uri.parse("content://com.android.calendar/events");
}
Calendar cal = Calendar.getInstance();
ContentValues event = new ContentValues();
event.put("calendar_id", 1);
event.put("title", "Event Title");
event.put("description", "Event Desc");
event.put("eventLocation", "Event Location");
event.put("dtstart",cal.getTimeInMillis());
event.put("rrule", "FREQ=WEEKLY;WKST=SU;BYDAY=WE");
event.put("allDay", 1); // 0 for false, 1 for true
event.put("eventStatus", 1);
event.put("hasAlarm", 1); // 0 for false, 1 for true
event.put("duration","P3600S");
Uri url = getContentResolver().insert(eventsUri, event);
}
}
这篇关于如何以编程方式添加周期性事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!