在日历中添加提醒时出现android.database.sqlite.SQLiteException

标签 android sqlite calendar reminders

 @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 帐户配置谷歌日历应用程序。
  • 如果您将错误的格式或错误的时间传递给事件或提醒。使用具有正确时区的 unix 时间。
  • 关于在日历中添加提醒时出现android.database.sqlite.SQLiteException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55021625/

    相关文章:

    android - 在android中的调用通知警报?

    sql - SQL查询以选择不喜欢颜色变体的颜色

    iPhone - 如何导入所有日历事件,包括事件 ID?

    Android SQlite OnUpgrade 问题

    calendar - RFC 5545 与 RFC 2445 有何不同

    php - Google Calendar API (v3) - PHP 可以写但不能读?

    java - 如何在Android中使用这些特殊字符?

    android - 使用 FFmpeg C API 调整视频大小

    android - 如何使用 ViewPager.OnPageChangeListener

    android - Android 中简单的数据库访问方法