gpt4 book ai didi

安卓 : Set reminder functionality

转载 作者:行者123 更新时间:2023-11-29 01:45:31 26 4
gpt4 key购买 nike

我正在开发一个具有提醒功能的应用程序。我使用的代码如下设置提醒和事件:

private void addReminder(int statrYear, int startMonth, int startDay, int startHour, int startMinut, String title){
// Convert start of begin time of reminder in milliseconds.
Calendar beginTime = Calendar.getInstance();
beginTime.set(statrYear, startMonth, startDay, startHour, startMinut);
long startMillis = beginTime.getTimeInMillis();

// String to access default google calendar of device for Event setting.
String eventUriString = "content://com.android.calendar/events";

// Creation of Event.
ContentValues eventValues = new ContentValues();
// Set calendar as 1 for default calendar.
eventValues.put(Events.CALENDAR_ID, 1);
// Set title as user define.
eventValues.put(Events.TITLE, title);
// Set description as user define.
eventValues.put(Events.DESCRIPTION, "MYApp");
// Set location as user define.
eventValues.put(Events.EVENT_TIMEZONE, "India");
// Set start time as system time or time converted in milliseconds.
eventValues.put(Events.DTSTART, startMillis);
// Set status of event as 1.
eventValues.put("eventStatus", 1);
// Set visibility of event as 3 (public).
eventValues.put("visibility", 3);
// Set transparency as 0. No other app seen through reminder.
eventValues.put("transparency", 0);
// Set alarm as 1. Ringing.
eventValues.put(Events.HAS_ALARM, 1);

// Set Event in calendar.
Uri eventUri = getContentResolver().insert(Uri.parse(eventUriString), eventValues);
// Getting ID of event in Long.
long eventID = Long.parseLong(eventUri.getLastPathSegment());

/***************** Event: Reminder(with alert) Adding reminder to event *******************/
// String to access default google calendar of device for reminder setting.
String reminderUriString = "content://com.android.calendar/reminders";
ContentValues reminderValues = new ContentValues();

// Set reminder on Event ID.
reminderValues.put("event_id", eventID);
// Set reminder minute before.
reminderValues.put("minutes", 1);
// Set method of reminder
reminderValues.put("method", 1);

@SuppressWarnings("unused")
//Setting reminder in calendar on Event.
Uri reminderUri = getContentResolver().insert(Uri.parse(reminderUriString), reminderValues);
}

以上代码运行正常。现在应用的需求是:

  1. 如何获取提醒 ID。
  2. 如何从上述代码以编程方式设置的日历中删除提醒。
  3. 如何以编程方式编辑现有提醒。
  4. 如何制作提醒,隐藏在日历中,仅在闹钟时间可见。

请指导我提出您的建议。

最佳答案

一个。如何获取提醒id。

您可以获得您的提醒 ID 为:

Long reminderID = Long.parseLong(reminderUri.getLastPathSegment());

B.如何从上面代码以编程方式设置的我的日历中删除提醒。

您可以通过调用以下代码从日历中删除提醒:

Uri reminderUri = Uri.parse("content://com.android.calendar/reminders");
reminderUri = Uri.withAppendedPath(reminderUri, String.valueOf(reminderID));
context.getContentResolver().delete(reminderUri, null, null);

C.如何以编程方式编辑现有提醒。

您可以通过以下代码在同一事件 ID 和提醒中设置新的更新字段来更新提醒:

更新事件

Uri updateEventUri = Uri.withAppendedPath(Uri.parse("content://com.android.calendar/events"), String.valueOf(eventID));
context.getContentResolver().update(updateEventUri, eventValues, null, null);

更新提醒

Uri updateReminderUri = Uri.withAppendedPath(Uri.parse("content://com.android.calendar/reminders"), String.valueOf(Utility.eventID));
context.getContentResolver().update(updateReminderUri, reminderValues, null, null);

关于安卓 : Set reminder functionality,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21795220/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com