简体   繁体   English

Android-添加没有提醒的日历活动

[英]Android - Adding a calendar event without reminder

I'm using the following function to add an event to calendar: 我正在使用以下功能将事件添加到日历:

public String addEventToCalendar(long startDate, long endDate, String recurrenceRule, boolean isAllDay, String title, String description, String location, long calendarID) {
    ContentResolver cr = context.getContentResolver();
    ContentValues values = new ContentValues();
    TimeZone timeZone = TimeZone.getDefault();
    values.put(CalendarContract.Events.DTSTART, startDate);
    values.put(CalendarContract.Events.DTEND, endDate);
    values.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());
    if (recurrenceRule != null)
        values.put(CalendarContract.Events.RRULE, recurrenceRule);
    values.put(CalendarContract.Events.TITLE, title);
    values.put(CalendarContract.Events.DESCRIPTION, description);
    values.put(CalendarContract.Events.CALENDAR_ID, calendarID);
    values.put(CalendarContract.Events.ALL_DAY, isAllDay);
    values.put(CalendarContract.Events.EVENT_LOCATION, location);
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
        return null; // we don't have the right permissions
    }
    Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
    String eventID = uri.getLastPathSegment();
    return eventID;
}

It works, but the resulting calendar event, have a 30 minutes reminder! 它有效,但是日历事件产生了30分钟的提醒! I'm not able to figure out why. 我不知道为什么。 Any clue please? 有什么线索吗? Thanks a lot. 非常感谢。

It seems like a default reminder is added after you insert your calendar event. 插入日历事件后,似乎添加了默认提醒。

What you could try is to check if there are any reminder associated with your event right after you inserted it. 您可以尝试的是在插入事件后立即检查是否有与事件关联的提醒。 And delete it if so. 并删除它(如果是)。

CalendarContract.Reminders.query(contentResolver, eventId, projection)

will give you a list of reminder associated with the eventId 将为您提供与eventId相关的提醒列表

If the Cursor contains any reminder you can delete it with : 如果游标包含任何提醒,则可以使用以下命令将其删除:

getContentResolver().delete(ContentUris.withAppendedId(CalendarContract.Reminders.CONTENT_URI, reminderId), null, null);

docs : http://developer.android.com/reference/android/provider/CalendarContract.Reminders.html docs: http : //developer.android.com/reference/android/provider/CalendarContract.Reminders.html

Try to add this 尝试添加这个

ContentValues values = new ContentValues();
values.put(CalendarContract.Events.HAS_ALARM, 0);

Whether the event has an alarm or not. 事件是否有警报。 Column name. 列名。

Type: INTEGER (boolean) 类型:INTEGER(布尔值)

public static final String HAS_ALARM = "hasAlarm"; 公共静态最终字符串HAS_ALARM =“ hasAlarm”;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM