我想通过意图插入日历活动。但是“添加事件” - 活动不应该预先填写提醒/警报。
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis())
.putExtra(Events.TITLE, title)
.putExtra(Events.DESCRIPTION, description)
.putExtra(Events.HAS_ALARM, false)
.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
此意图将启动日历的“添加事件” - 预先填充一些数据的活动。但是,虽然我将Events.HAS_ALARM
设置为false,但活动预先填充了提醒(在Android ICS上测试)。
更糟糕的是,提醒事件预先填充到活动前10分钟,如果全天活动真的很糟糕。谁想在第二天晚上11点50分提醒你?
我在这里缺少什么?
答案 0 :(得分:6)
我从未尝试过你的技术。以下是我用来保存日历的代码段。
public static void saveCalendar(Context ctx, String title,
String description, String location, Calendar cal_start,
Calendar cal_end) {
// look for calendar
Cursor cursor = ctx.getContentResolver()
.query(Uri.parse("content://com.android.calendar/calendars"),
new String[] { "_id", "displayname" }, "selected=1",
null, null);
cursor.moveToFirst();
String[] CalNames = new String[cursor.getCount()];
int[] CalIds = new int[cursor.getCount()];
for (int i = 0; i < CalNames.length; i++) {
CalIds[i] = cursor.getInt(0);
CalNames[i] = cursor.getString(1);
cursor.moveToNext();
}
cursor.close();
// put calendar event
ContentValues event = new ContentValues();
event.put("calendar_id", CalIds[0]);
event.put("title", title);
event.put("description", description);
event.put("eventLocation", location);
event.put("dtstart", cal_start.getTimeInMillis());
event.put("dtend", cal_end.getTimeInMillis());
event.put("hasAlarm", 1);
Uri eventsUri = Uri.parse("content://com.android.calendar/events");
Uri newEvent = ctx.getContentResolver().insert(eventsUri, event);
// put alarm reminder for an event, 2 hours prior
long eventID = Long.parseLong(newEvent.getLastPathSegment());
ContentValues cv_alarm = new ContentValues();
cv_alarm.put("event_id", eventID);
cv_alarm.put("method", 1);
cv_alarm.put("minutes", 120);
ctx.getContentResolver()
.insert(Uri.parse("content://com.android.calendar/reminders"),
cv_alarm);
}
您不希望警报/提醒设置为0到hasAlarm并且不要添加代码来添加警报。它对我有用。
答案 1 :(得分:3)
列HAS_ALARM需要一个0或1的整数布尔值。
intent.putExtra(Events.HAS_ALARM, 0);