How to add calendar events in Android?

前端 未结 10 1231
太阳男子
太阳男子 2020-11-22 13:31

I\'m just getting up to speed on Android, and today in a project meeting someone said that Android has no native calendar app so users just use whatever calendar app they li

10条回答
  •  太阳男子
    2020-11-22 14:29

    Try this ,

       Calendar beginTime = Calendar.getInstance();
        beginTime.set(yearInt, monthInt - 1, dayInt, 7, 30);
    
    
    
        ContentValues l_event = new ContentValues();
        l_event.put("calendar_id", CalIds[0]);
        l_event.put("title", "event");
        l_event.put("description",  "This is test event");
        l_event.put("eventLocation", "School");
        l_event.put("dtstart", beginTime.getTimeInMillis());
        l_event.put("dtend", beginTime.getTimeInMillis());
        l_event.put("allDay", 0);
        l_event.put("rrule", "FREQ=YEARLY");
        // status: 0~ tentative; 1~ confirmed; 2~ canceled
        // l_event.put("eventStatus", 1);
    
        l_event.put("eventTimezone", "India");
        Uri l_eventUri;
        if (Build.VERSION.SDK_INT >= 8) {
            l_eventUri = Uri.parse("content://com.android.calendar/events");
        } else {
            l_eventUri = Uri.parse("content://calendar/events");
        }
        Uri l_uri = MainActivity.this.getContentResolver()
                .insert(l_eventUri, l_event);
    

提交回复
热议问题