Retrieve the default calendar id in Android

前端 未结 5 689
走了就别回头了
走了就别回头了 2021-01-04 02:51

I have the following code for adding event to calendar.

The problem is that I don\'t know how to retrieve the default calendar id.

l         


        
5条回答
  •  感动是毒
    2021-01-04 03:32

    Some latest versions have issue, there is different visible calendar list so below is the code to select PRIMARY calendar and in older devices this query return 0 record, so used second one if 1st one return 0 records.

    Cursor calCursor = mContext.getContentResolver().query(CalendarContract.Calendars.CONTENT_URI, projection, CalendarContract.Calendars.VISIBLE + " = 1 AND "  + CalendarContract.Calendars.IS_PRIMARY + "=1", null, CalendarContract.Calendars._ID + " ASC");
    if(calCursor.getCount() <= 0){
        calCursor = mContext.getContentResolver().query(CalendarContract.Calendars.CONTENT_URI, projection, CalendarContract.Calendars.VISIBLE + " = 1", null, CalendarContract.Calendars._ID + " ASC");
    }
    

提交回复
热议问题