簡體   English   中英

Android-添加沒有提醒的日歷活動

[英]Android - Adding a calendar event without reminder

我正在使用以下功能將事件添加到日歷:

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;
}

它有效,但是日歷事件產生了30分鍾的提醒! 我不知道為什么。 有什么線索嗎? 非常感謝。

插入日歷事件后,似乎添加了默認提醒。

您可以嘗試的是在插入事件后立即檢查是否有與事件關聯的提醒。 並刪除它(如果是)。

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

將為您提供與eventId相關的提醒列表

如果游標包含任何提醒,則可以使用以下命令將其刪除:

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

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

嘗試添加這個

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

事件是否有警報。 列名。

類型:INTEGER(布爾值)

公共靜態最終字符串HAS_ALARM =“ hasAlarm”;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM