对于第一个if条件(routineObject.getSchedule()== 1)数据进入日历事件但是对于其他条件,它进入生日而不是事件。我希望所有这些都成为事件或提醒。
任何解决方案?
String eventUriString = "content://com.android.calendar/events";
ContentResolver cr = this.getContentResolver();
ContentValues values = new ContentValues();
if (routineObject.getSchedule() == 1) {
dateTimeString = dateString + " " + SelectedTime;
Date dateDateTime;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH : mm");
try {
dateDateTime = sdf.parse(dateTimeString);
} catch (ParseException e) {
e.printStackTrace();
dateDateTime = new Date();
}
long millisecondsTimesNew = dateDateTime.getTime();
values.put(CalendarContract.Reminders.CALENDAR_ID, routineObject.getId());
values.put(CalendarContract.Reminders.TITLE, "Routineer");
values.put(CalendarContract.Reminders.DTSTART, millisecondsTimesNew);
values.put(CalendarContract.Reminders.DESCRIPTION, todoTextOneTIme);
values.put(CalendarContract.Reminders.DTEND, millisecondsTimesNew);
values.put(CalendarContract.Reminders.HAS_ALARM, true);
values.put(CalendarContract.Reminders.EVENT_TIMEZONE, TimeZone.getDefault().getID());
} else if (routineObject.getSchedule() == 2) {
Date mDate;
SimpleDateFormat sdfdate = new SimpleDateFormat("yyyy-MM-dd");
try {
mDate = sdfdate.parse(endDate);
} catch (ParseException e) {
e.printStackTrace();
mDate = new Date();
}
long EndtimeInMilliseconds = mDate.getTime();
dateTimeStringEveryday = startDate + " " + SelectedTime;
Date dateDateTimeEveryday;
SimpleDateFormat sdfEveryday = new SimpleDateFormat("yyyy-MM-dd HH : mm");
try {
dateDateTimeEveryday = sdfEveryday.parse(dateTimeStringEveryday);
} catch (ParseException e) {
e.printStackTrace();
dateDateTimeEveryday = new Date();
}
long millisecondsStartTimesEveryday = dateDateTimeEveryday.getTime();
values.put(CalendarContract.Reminders.CALENDAR_ID, routineObject.getId());
values.put(CalendarContract.Reminders.TITLE, "Routine Everyday");
values.put(CalendarContract.Reminders.DTSTART, millisecondsStartTimesEveryday);
values.put(CalendarContract.Reminders.HAS_ALARM, true);
values.put(CalendarContract.Reminders.RRULE, "FREQ=DAILY"); //UNTIL=1924885800000
values.put(CalendarContract.Reminders.DTEND,EndtimeInMilliseconds);
values.put(CalendarContract.Reminders.DESCRIPTION, todoTextEveryDay);
values.put(CalendarContract.Reminders.EVENT_TIMEZONE, TimeZone.getDefault().getID());
}
Uri eventUriOneTime = this.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), values);
eventID = Long.parseLong(eventUriOneTime.getLastPathSegment());
alertSelection();
答案 0 :(得分:1)
你们代码的主要罪魁祸首是:
values.put(CalendarContract.Reminders.CALENDAR_ID, routineObject.getId());
在大小写
中设置例程对象的ID时出现问题Some devices uses calendar id = 1 for birthdays but generally not.
这就是将你的事件推入生日日历的原因,你可能已经将例程对象的Id设置为1,而你创建了Java对象。
请为您不想进入生日的常规对象设置相应的Id不等于1。