@SuppressLint({"RxLeakedSubscription", "RxSubscribeOnError"})
public static long pushAppointmentsToCalender(Activity curActivity, String title, String addInfo, String place, int status, long startDate, boolean needReminder) {
/***************** Event: note(without alert) *******************/
ContentResolver cr = curActivity.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, startDate);
values.put(CalendarContract.Events.DTEND, startDate);
values.put(CalendarContract.Events.TITLE, title);
values.put(CalendarContract.Events.DESCRIPTION, addInfo);
values.put(CalendarContract.Events.CALENDAR_ID, startDate);
values.put(CalendarContract.Events.EVENT_TIMEZONE, "Asia/Calcutta");
@SuppressLint("MissingPermission") Uri uriEvent = cr.insert(CalendarContract.Events.CONTENT_URI, values);
long eventID = Long.parseLong(uriEvent.getLastPathSegment());
try {
if (needReminder) {
ContentResolver crreminder = curActivity.getContentResolver();
ContentValues valuesreminder = new ContentValues();
valuesreminder.put(CalendarContract.Reminders.EVENT_ID, eventID);
valuesreminder.put(CalendarContract.Reminders.MINUTES, 15);
valuesreminder.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
@SuppressLint("MissingPermission") Uri uri = crreminder.insert(CalendarContract.Reminders.CONTENT_URI, valuesreminder);
}
}catch (Exception e){
e.printStackTrace();
}
return eventID;
}
我在日志中遇到的错误是
2019-03-06 16:29:16.935 23021-23021/com.medikoe.connect.debug W/System.err: android.database.sqlite.SQLiteException
2019-03-06 16:29:16.936 23021-23021/com.medikoe.connect.debug
事件 id 已成功创建,但在插入 uri 进行提醒时正在创建 sqlite 异常。请帮忙!
最佳答案
Update: I found that this error can be occurred with in two conditions.
电话/模拟器会发生此错误。然后确保在运行应用程序之前使用 gmail 帐户配置谷歌日历应用程序。
关于在日历中添加提醒时出现android.database.sqlite.SQLiteException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55021625/