添加事件和提醒不能在6.0棉花糖工作 [英] Add event and reminder not working in 6.0 marshmallow
问题描述
我试图在
日历
中添加事件,还有提醒
。除了 Marshmallow - 6.0
当我尝试添加事件时,它可以在所有设备中正常工作在这里返回我的活动ID。即使我在这里获得事件ID,我看不到在我的日历中添加的事件
ContentValues event = new ContentValues();
event.put(calendar_id,1);
event.put(title,Match);
event.put(description,PTGConstantMethod.validateString(match.getMatch_name()));
event.put(eventLocation,match.getVenue());
event.put(eventTimezone,TimeZone.getDefault()。getID());
event.put(dtstart,startDate.getTime());
event.put(dtend,endDate);
event.put(allDay,0); // 0为false,1为true
event.put(eventStatus,1);
event.put(hasAlarm,1); // 0为false,1为true
Uri eventUri = context.getApplicationContext()
.getContentResolver()
.insert(Events.CONTENT_URI,event);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
我在这里添加提醒,
ContentValues提醒=新的ContentValues();
prompters.put(event_id,eventID);
alertsers.put(method,CalendarContract.Reminders.METHOD_ALERT);
alertsers.put(分钟,分钟);
context.getApplicationContext()。getContentResolver()
.insert(Reminders.CONTENT_URI,提醒);
但是在添加提醒时应用程序崩溃。这是我的日志。
android.database.sqlite.SQLiteException
在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java :179)
在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
在android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
在android.content。 ContentResolver.insert(ContentResolver.java:1231)
在我的build.gradle
minSdkVersion 14
targetSdkVersion 22
I最后发现没有任何日历与 event.put(calendar_id,1);
。那么我如何获得应用程序默认日历?
我尝试添加新的日历并添加事件。
ContentValues calendar = new ContentValues();
calendar.put(CalendarContract.Calendars.NAME,context.getResources()。getString(R.string.app_name));
calendar.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,context.getResources()。getString(R.string.app_name)+Calendar);
calendar.put(CalendarContract.Calendars.VISIBLE,true);
Uri uri = context.getApplicationContext()
.getContentResolver()
.insert(CalendarContract.Calendars.CONTENT_URI,calendar);
long calendarId = Long.parseLong(uri.getLastPathSegment());
但我无法在我的日历应用程序中看到这个日历。当我尝试使用这个新的日历添加事件。事件得到显示,但点击事件,我的默认日历应用程序崩溃。添加新的日历到默认日历应用程序时我做错了什么?谢谢。
对于以这种方式发布答案,但是我在Android M日历中手动添加事件时发现了说我们需要添加帐户到日历帐户才能添加事件。所以我猜测,除非我们不添加或将日历映射到至少一个帐户,否则我们无法手动或以编程方式向Android M设备日历添加事件。
I am facing on weird issue.
I am trying to add events in calendar
and also reminder
. It's working fine in all devices except the one having Marshmallow - 6.0
When i try to add events, it also returns me event id here. And even though i am getting event id here, I can not see events added in my calendar
ContentValues event = new ContentValues();
event.put("calendar_id", 1);
event.put("title", "Match");
event.put("description",PTGConstantMethod.validateString(match.getMatch_name()));
event.put("eventLocation", match.getVenue());
event.put("eventTimezone", TimeZone.getDefault().getID());
event.put("dtstart", startDate.getTime());
event.put("dtend", endDate);
event.put("allDay", 0); // 0 for false, 1 for true
event.put("eventStatus", 1);
event.put("hasAlarm", 1); // 0 for false, 1 for true
Uri eventUri = context.getApplicationContext()
.getContentResolver()
.insert(Events.CONTENT_URI, event);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
I am adding reminder here,
ContentValues reminders = new ContentValues();
reminders.put("event_id", eventID);
reminders.put("method", CalendarContract.Reminders.METHOD_ALERT);
reminders.put("minutes", minutes);
context.getApplicationContext().getContentResolver()
.insert(Reminders.CONTENT_URI, reminders);
But app crashes while adding reminder. Here are my logs.
android.database.sqlite.SQLiteException at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476) at android.content.ContentResolver.insert(ContentResolver.java:1231)
In my build.gradle
minSdkVersion 14
targetSdkVersion 22
I finally found that there isn't any calendar with event.put("calendar_id", 1);
. So how could i get app default calendar?
I tried by adding new calendar and add events to that.
ContentValues calendar = new ContentValues();
calendar.put(CalendarContract.Calendars.NAME, context.getResources().getString(R.string.app_name));
calendar.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, context.getResources().getString(R.string.app_name)+" Calendar");
calendar.put(CalendarContract.Calendars.VISIBLE, true);
Uri uri = context.getApplicationContext()
.getContentResolver()
.insert(CalendarContract.Calendars.CONTENT_URI, calendar);
long calendarId = Long.parseLong(uri.getLastPathSegment());
But i am not able to see this calendar in my calendar app. When i try to add events using this new calendar. Events get display but on click of event, my default calendar app gets crashed. What i am doing wrong while adding new calendar to default calendar app? Thanks.
Sorry for posting answer in such a way,but what I found while adding event manually in Android M calendar, it says that we need to add account to calendar account in order to add events. So I am guessing that unless and until we do not add or map a calendar to at least one account, we cannot add events manually or programmatically to Android M device calendar.
这篇关于添加事件和提醒不能在6.0棉花糖工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!