'How do I access all available event color keys that are available in the CalendarContract.EventColumn?
I am trying to work with the CalendarContract class provided by Google for Android. I've hit a block trying to figure out how to access which colors I can apply to an event. You can see a list of colors you can apply to an event if you go to the add event screen on either Android's Calendar app or on the web-version of the Google calendar.
I can see there is a list of available colors to choose from, and I want to know if there is a way to get that list programmatically. I don't want to assume I can add any color I want.
One thing I've tested when adding an event is just passing in a random int using the ContentValues object:
ContentValues l_event = new ContentValues();
l_event.put(CalendarContract.Events.CALENDAR_ID, calID);
l_event.put(CalendarContract.Events.TITLE, eventName);
l_event.put(CalendarContract.Events.DESCRIPTION, "This is test event");
l_event.put(CalendarContract.Events.EVENT_LOCATION, "UCLA");
l_event.put(CalendarContract.Events.DTSTART, beginTime.getTimeInMillis());
l_event.put(CalendarContract.Events.DTEND, beginTime.getTimeInMillis());
l_event.put(CalendarContract.Events.EVENT_COLOR_KEY, 1);
Uri l_eventUri = Uri.parse("content://com.android.calendar/events");
Uri l_uri = context.getContentResolver().insert(l_eventUri, l_event);
I tried playing around with the line
l_event.put(CalendarContract.Events.EVENT_COLOR_KEY, 1);
by passing in different integers. It looks like lower values work, like 1 and 2 (I get different event colors with those values). But if I pass in 100, it breaks. This is where I'm trying to make this work. I want to know how to query the Calendar so I know how many colors I have to work with.
Does anyone have any experience with this? Or am I going about this all wrong?
Solution 1:[1]
Google Calendar colors for CalendarContract.Events.EVENT_COLOR_KEY column:
Color ID Color Name Hex Code
1 Lavender #7986cb
2 Sage #33b679
3 Grape #8e24aa
4 Flamingo #e67c73
5 Banana #f6c026
6 Tangerine #f5511d
7 Peacock #039be5
8 Graphite #616161
9 Blueberry #3f51b5
10 Basil #0b8043
11 Tomato #d60000
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lior Iluz |
