您好我正在Android上实施生日提醒应用程序。请告诉我在日历上设置提醒的步骤是什么。我已经在android中获得了日历。
答案 0 :(得分:1)
您可以使用此功能在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();
}