【发布时间】:2017-05-29 17:01:06
【问题描述】:
在 api 22 之前,事件会正确添加到日历中。
我还为 Marshmallow 实现了运行时权限,我的应用程序的电话设置中允许日历权限清晰可见。
但手机日历上仍然没有更新,应用程序也没有给出错误或警告。
以下是我在手机日历上以编程方式添加事件的方法。
private void addEventToCalender(Activity ourActivity, String title, String desc, String place, int status, long startDate, long endDte, boolean needReminder, boolean needMailService) {
try {
String eventUriString = "content://com.android.calendar/events";
ContentValues eventValues = new ContentValues();
eventValues.put("calendar_id", 1); // id, We need to choose from // our mobile for primary its 1
eventValues.put("title", "My Title");
eventValues.put("description","My Description" );
eventValues.put("eventLocation", "Noida,UP ";
eventValues.put("dtstart", startDate);
eventValues.put("dtend", endDte);
eventValues.put("allDay", 1); // 1 for whole day
//eventValues.put("rrule", "FREQ=YEARLY");
// values.put("allDay", 1); //If it is bithday alarm or such
// kind (which should remind me for whole day) 0 for false, 1
// for true
eventValues.put("eventStatus", 1); // This information is
// sufficient for most
// entries tentative (0),
// confirmed (1) or canceled
// (2):
eventValues.put("eventTimezone", "UTC/GMT " + Constants.tzone);
eventValues.put("hasAlarm", 1); // 0 for false, 1 for true
Uri eventUri = this.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), eventValues);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
Log.i("eventID", eventID + "");
showSnackBar("Event added to calender successfuly.");
} catch (Exception ex) {
Log.e("error", "Error in adding event on calendar" + ex.getMessage());
showSnackBar("Ünable to add event to calender!");
}
}
【问题讨论】:
-
以上代码没有问题,问题出在谷歌日历应用最新更新上,所以卸载最新更新后,我现在可以在棉花糖上添加多个事件。
标签: android