我没有为我的活动设定时间。它只是没有预设。这是我的代码:
private void makeCalendarEvent() {
int year, month, month1, month2, day;
day = Integer.parseInt(Character.toString(date.charAt(4)) + Character.toString(date.charAt(5)));
month1 = Integer.parseInt(Character.toString(date.charAt(7)));
month2 = Integer.parseInt(Character.toString(date.charAt(8)));
year = Integer.parseInt(Character.toString(date.charAt(10)) + Character.toString(date.charAt(11)));
Log.e("month", String.valueOf(month1 + month2));
Log.e("year", String.valueOf(year));
Log.e("day", String.valueOf(day));
switch (month2) {
case 1:
if (month1 == 1) {
month = Calendar.NOVEMBER;
} else {
month = Calendar.JANUARY;
}
break;
case 2:
if (month1 == 1) {
month = Calendar.DECEMBER;
} else {
month = Calendar.FEBRUARY;
}
break;
case 3:
month = Calendar.MARCH;
break;
case 4:
month = Calendar.APRIL;
break;
case 5:
month = Calendar.MAY;
break;
case 6:
month = Calendar.JUNE;
break;
case 7:
month = Calendar.JULY;
break;
case 8:
month = Calendar.AUGUST;
break;
case 9:
month = Calendar.SEPTEMBER;
break;
case 10:
month = Calendar.OCTOBER;
break;
default:
month = Calendar.JANUARY;
}
Log.e("calendar", String.valueOf(month));
Calendar beginTime = Calendar.getInstance();
beginTime.clear();
beginTime.set(20 + year, month, day, 23, 0);
Calendar endTime = Calendar.getInstance();
endTime.clear();
endTime.set(20 + year, month, day + 1, 5, 0);
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(CalendarContract.Events.CONTENT_URI)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis())
.putExtra(CalendarContract.Events.TITLE, head)
.putExtra(CalendarContract.Events.DESCRIPTION, body)
.putExtra(CalendarContract.Events.EVENT_LOCATION, "Club Douala Ravensburg");
startActivity(intent);
}
我的日志输出:
03-13 22:34:28.787 6919-6919/? E/month﹕ 3
03-13 22:34:28.787 6919-6919/? E/year﹕ 14
03-13 22:34:28.787 6919-6919/? E/day﹕ 13
03-13 22:34:28.787 6919-6919/? E/calendar﹕ 2
因此Month
,Day
,Hour
和Minute
未设置。不知道Year
,但我猜这也忽略了
任何想法我做错了什么?
答案 0 :(得分:1)
我猜你已经搞砸了一年。例如。对于2014年,您设置20 + 14 = 34.我认为如果您的年份超过1970年,则无法设置。