android.database.sqlite.SQLiteException while adding reminder in calendar

£可爱£侵袭症+ 提交于 2019-12-10 20:53:48

问题


 @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;
}

The error i am getting in logs is

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 

Event id is created successfully but while inserting uri for reminder is creating sqlite exception . Please help!


回答1:


Update: I found that this error can be occurred with in two conditions.

  1. If you didn't config your google calendar app in your phone/emulator this error will occur. Then make sure that you configure the google calendar app with a gmail account before running the app.

  2. If you are passing wrong formatted or false time to the event or reminder. use unix time with correct time zone.



来源:https://stackoverflow.com/questions/55021625/android-database-sqlite-sqliteexception-while-adding-reminder-in-calendar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!