如果用户愿意,我需要在默认的 android 日历中添加一个重复事件并对其进行修改。我需要直接执行此操作,即无需打开日历意图。我使用了以下代码。Toast 显示最后添加的事件的事件 ID,但该事件未显示在电话日历中。真的很困扰,但无法解决问题..请帮助..
public void createEvent(String title, String location, String description){
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("GMT-1"));
Date dt = null;
Date dt1 = null;
String Stime="2013-11-13 07:30";
String Etime="2013-11-13 08:00";
try {
dt = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(Stime);
dt1 = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(Etime);
Calendar beginTime = Calendar.getInstance();
cal.setTime(dt);
// beginTime.set(2013, 7, 25, 7, 30);
beginTime.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),
cal.get(Calendar.MINUTE));
Calendar endTime = Calendar.getInstance();
cal.setTime(dt1);
// endTime.set(2013, 7, 25, 14, 30);
// endTime.set(year, month, day, hourOfDay, minute);
endTime.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),
cal.get(Calendar.MINUTE));
ContentResolver cr = this.getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, beginTime.getTimeInMillis());
values.put(Events.DTEND, endTime.getTimeInMillis());
values.put(Events.TITLE, title);
values.put(Events.DESCRIPTION, description);
values.put(Events.CALENDAR_ID, 3 );
// values.put(Events._ID, meeting_id);
values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
Uri uri = cr.insert(Events.CONTENT_URI, values);
long eventID = Long.parseLong(uri.getLastPathSegment());
Toast toast =Toast.makeText(getApplicationContext(), "Calender Event Added" + eventID,Toast.LENGTH_LONG);
toast.show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
另外我必须在低于 14 的 android 版本中使用相同的东西。我应该用什么更新代码?谢谢..