我想通过故意插入一个日历事件。但添加事件-activity不应该pfilled与提醒/报警器$ P $。
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);
此意图将启动日历的pfilled一些数据添加事件-activity $ P $。不过,虽然我设置 Events.HAS_ALARM
为false,该活动是pre-填充提醒(在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).
什么是连价值,是提醒ppopulated到10分钟的事件之前,这情况下,一个全天事件实在是太差了$ P $。谁愿意在十一时五十分事件的第二天提醒?
What's even worth, 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?
我很想念在这里?
我从来没有尝试过上面的方法。下面是我用它来保存日历code段。
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到hasAlarm,不要把codeS添加报警。这对我的作品。
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.