Ich verwende einen Code, um dem Kalender des Geräts ein Ereignis hinzuzufügen. Der Code funktioniert in allen Android-Versionen außer Android M. Das Ereignis, wenn es auf Android M hinzugefügt wird, wird als Geburtstag statt als Ereignis angezeigt. Bitte helfen Sie, wie dieses Problem behoben werden kann.Problem beim Hinzufügen eines Kalenderereignisses in Android M
Der Code verwendet wird, ist als
// Add event to calendar
try {
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, startDateInMilliSeconds);
values.put(CalendarContract.Events.DTEND, endDateInMilliSeconds);
values.put(CalendarContract.Events.TITLE, title);
values.put(CalendarContract.Events.DESCRIPTION, description);
if (location != null && (!TextUtils.isEmpty(location))) {
values.put(CalendarContract.Events.EVENT_LOCATION, location);
}
values.put(CalendarContract.Events.CALENDAR_ID, 1);
values.put(CalendarContract.Events.EVENT_TIMEZONE, Calendar.getInstance()
.getTimeZone().getID());
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
// Save the eventId into the Task object for possible future delete.
long eventId = Long.parseLong(uri.getLastPathSegment());
Uri openCalendarEvent = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventId);
Intent calIntent = new Intent(Intent.ACTION_VIEW).setData(uri);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startDateInMilliSeconds);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endDateInMilliSeconds);
calIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(calIntent);
} catch (Exception e) {
e.printStackTrace();
}
Versuch unter Methode –