gpt4 book ai didi

android - 如何在日历中添加提醒

转载 作者:行者123 更新时间:2023-11-30 04:16:44 29 4
gpt4 key购买 nike

您好,我正在 Android 上实现生日提醒应用程序。请告诉我在日历上设置提醒的程序是什么。我已经在 android 中获取了日历。

最佳答案

您可以使用它在 Android 日历中添加事件。

GregorianCalendar startDate = new GregorianCalendar(Locale.ENGLISH);
startDate = CustomDateFormatter.formatScheduleDate(schedule.getScheduleStartDate());

GregorianCalendar endDate = new GregorianCalendar(Locale.ENGLISH);
endDate = CustomDateFormatter.formatScheduleDate(schedule.getScheduleEndDate());

try{

String[] projection = new String[] { "_id", "name" };
Uri calendars = Uri.parse("content://com.android.calendar/calendars");
Cursor managedCursor = mContext.getContentResolver().query(calendars, projection, "selected=1", null, null);
ContentValues event = new ContentValues();

long StartTime = startDate.getTimeInMillis();
long EndTime = endDate.getTimeInMillis();
// int nameColumn = managedCursor.getColumnIndex("name");
int idColumn = managedCursor.getColumnIndex("_id");

if(managedCursor.moveToFirst()){

// String calName = managedCursor.getString(nameColumn);
String calId = managedCursor.getString(idColumn);

// Log.e("Cal name", calName);

event.put("calendar_id", calId);
event.put("title", schedule.getScheduleType());
event.put("description", schedule.getScheduleTextContent());
event.put("dtstart", StartTime );
event.put("dtend", EndTime);
event.put("hasAlarm", 1);

Uri eventsUri = Uri.parse("content://com.android.calendar/events");
Uri calUri = mContext.getContentResolver().insert(eventsUri, event);

Uri remindersUri = Uri.parse("content://com.android.calendar/reminders");
event = new ContentValues();
event.put("event_id", Long.parseLong(calUri.getLastPathSegment()));
// Log.d("Event ID: ", calUri.getLastPathSegment());

event.put("method",1);
event.put("minutes",0);

mContext.getContentResolver().insert(remindersUri, event);
}

managedCursor.close();

}catch(Exception ex){
ex.printStackTrace();
}

关于android - 如何在日历中添加提醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9859462/

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