Android插入日历意图 - 没有报警/提醒 [英] Android Insert Calendar Intent - Without alarm/reminder
问题描述
我想通过intent插入日历事件。但是添加事件 - 活动不应该预先填充提醒/警报。
I want to insert a calendar event via intent. But the "add event"-Activity should not be prefilled with a reminder/alarm.
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上测试)。
This intent will start the calendar's "add event"-activity prefilled with some data. However, although I set Events.HAS_ALARM
to false, the activity is pre-populated with a reminder (tested on Android ICS).
更糟糕的是,提醒是在活动前10分钟预先填好的,如果全天活动真的很糟糕。谁想在下午11点50分举行活动?
What's even worse, the reminder is prepopulated to 10 minutes before the event, which in case of an all-day event is really bad. Who wants to be reminded at 11.50 pm of an event the next day?
我在这里缺少什么?
推荐答案
我从来没有尝试过你的技术。这是我用来保存日历的代码片段。
I never tried your technique above. Here is the code snippet I use to save Calendar.
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 to hasAlarm和不要把代码添加报警。它适用于我。
It you don't want the alarm/reminder set 0 to hasAlarm and don't put the codes to add the alarm. It works for me.
这篇关于Android插入日历意图 - 没有报警/提醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!