我正在开发一款应用程序,用于在 native Google 日历中创建、更新和删除事件。 我正在通过以下代码创建一个事件:
ContentValues cvEvent = new ContentValues();
cvEvent.put(Events.DTSTART, startMillis);
cvEvent.put(Events.DTEND, endMillis);
cvEvent.put(Events.TITLE, strJobName);
cvEvent.put(Events.CALENDAR_ID, mlCalendarID);
cvEvent.put(Events.EVENT_TIMEZONE, "America/Los_Angeles");
Uri uriEvent = crEvent.insert(Events.CONTENT_URI, cvEvent);
但问题是此事件创建了用户在其日历 (Google) 中设置的默认提醒。
我还允许用户在我的应用中添加提醒。因此,当他添加提醒时,我会将提醒插入到默认的 Google 日历中。那没有问题。但是当用户没有在我的应用程序中添加任何提醒时,默认的谷歌日历会创建默认提醒。谁能告诉我如何解决这个问题?
P.S:我没有使用同步适配器。我通过自己的逻辑创建和删除事件和提醒。
我试过用
values.put(Events.HAS_ALARM, 0);
但是,这是没有用的。
最佳答案
如何使用插入事件后获得的事件 ID 以编程方式删除提醒?
ContentValues cvEvent = new ContentValues();
cvEvent.put(Events.DTSTART, startMillis);
cvEvent.put(Events.DTEND, endMillis);
cvEvent.put(Events.TITLE, strJobName);
cvEvent.put(Events.CALENDAR_ID, mlCalendarID);
cvEvent.put(Events.EVENT_TIMEZONE, "America/Los_Angeles");
Uri uriEvent = crEvent.insert(Events.CONTENT_URI, cvEvent);
//added code
long eventID = Long.parseLong(uri.getLastPathSegment());
ContentResolver cr = getContentResolver();
cr.delete(Reminders.CONTENT_URI, Reminders.EVENT_ID+"=?", new String[]{eventID+""});
关于android - 在没有默认提醒的情况下从我的应用程序创建日历事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19019932/