Create syncable android calendar programmatically - android

i developed an app-feature to create and sync a local phone calendar through an app. Now i have to sync this calendar online, best through the native phone account.
I tried to extend the URI's content values parameter (see API LVL < 8 parameter list below) by the account name and type but running after that into calendar freezes.
_id
sync_account
_sync_account_type
_sync_id
_sync_version
_sync_time
_sync_local_id
_sync_dirty
_sync_mark
url
name
displayName
hidden
color
access_level
selected
sync_events
location
timezone
ownerAccount
Is there another way to create an online syncable google calendar?

You cannot create a new one programatically.
Instead parse all available ones with
Uri.parse("content://com.android.calendar/calendars",null, null, null, null);
and fill in your events into a existing one.
But ensure, that your event got the same
sync_account
and
_sync_account_type

Related

Why does .event.set("fieldName", ObjectValue) not storing any data in Google Calendar API android?

I successfully intergarted Google Calendar API. I'm able to do CRUD. But now because of some requirements, I want to send some unique id to each events while creating from android app. For that I found one method called .set() this is a key value pair.
Event event = new Event()
.set("appointment_id", 55475)
.setSummary(summary)
.setLocation(location)
.setDescription(des);
But while fetching, I'm getting all data except event.get("appointment_id")
Why, even it is setting also. [If I'm doing here before executing insert like this: evetn.get("appointment_id"), I'm getting value, because this is locally I'm chocking]
I checked through debugging as well. See below:
But, I'm not getting when I'm fetching all events from Google calendar:
List<Event> items = events.getItems();
You are using the set method, but this is just an override of the com.google.api.client.json.GenericJson class, I believe this will only add this key-value to the final JSON which will be ignored by the API (as it is not an expected field).
Sincerely I don't know what is the point on creating a custom id when there is one directly integrated in calendar.
If you take a look at the insert method you can see that there is one field called id:
Opaque identifier of the event. When creating new single or recurring events, you can specify their IDs. Provided IDs must follow these rules:
characters allowed in the ID are those used in base32hex encoding, i.e. lowercase letters a-v and digits 0-9, see section 3.1.2 in RFC2938
the length of the ID must be between 5 and 1024 characters
the ID must be unique per calendar
Also in the same description for the field:
If you do not specify an ID, it will be automatically generated by the server.
My point being that if you need unique ID for events in calendar there is a built in method that will create them for you. And even if you need to supply your own id's you can do so informing this field.
Let me suggest you the official guide on event creation in which there is a more detailed view on the option you can take creating an Event.
Also look at the documentation for setId as this is the method you should be using instead of set.
Example:
Event event = new Event()
.setId("55475") // This has to be type String
.setSummary(summary)
.setLocation(location)
.setDescription(des);

Using preset event colors of google calendar in ContentValues

Any way to use some of the preset colors provided by google calendar while creating events by configuring ContentValues.
I tried using
ContentValues event = new ContentValues();
event.put("eventColor", 0xffff3300);
But this changes back to default on click of the event
You can set the color of the event through the optional colorId property. To check the valid values of color, you can go to the colors endpoint and use get method to list all the available colors.
Also, you may also be interested to look from the Android Open Source Project and this SO post.

How to categorize calendar events in Android?

I intend to create an Android Application which manages Calendar Events. Unfortunately, I don't see a way in which I can present the user a way to add events for a given category, that the user might create.
Link to CalendarContracts.Events in official Android Documentation
The CalendarProcider.Events table doesn't seem to have any field, where I can store the category the event belongs to. Should I create a new calendar, linked to the same account, for each new category that I'd like to create? Is that the only way, if not the recommended one?
http://android.calengoo.com/pagedoc/pageinstallation/pageeventcolors/pageeventcolors.html
This link here argues that, perhaps different calendars should be created to represent the different categories.
Calendars in Google Calendar are like categories for your events. Just create additional calendars to categorize your events. E.g. you could create calendars named "Work", "Home", "Family", "Sports", "TV" and so on. By saving an event into a calendar the event will be displayed with the color of the calendar. An additional advantage when assigning colors to your events this way is that you can easily hide certain calendars/categories with a single tap by using the calendar selection bar.
I feel the reasoning is perfectly sane, and would provide the same functionality, unless there is another legit way to create categories within the same calendar.

Android google calendar deleting future instances of recurring event

I'm trying to delete future instances of a google calendar recurring (repeated) event pro-grammatically using content resolver.
And to do this i have updated the rRule of the event , so for example if want to delete future instances of an event starting from date 11/11/2016
i edit the rRule string to look like so:
FREQ=DAILY;UNTIL=20161111;WKST=SU
However , when viewing google calendar application i find no changes and i find the event color only has changed to black color.
Some notes to keep in mind:
1- I'm using a third party library to so :
https://github.com/EverythingMe/easy-content-providers
CalendarProvider calendarProvider = new CalendarProvider(context);
Event event = calendarProvider.getEvent(eventId);
event.rRule = "FREQ=DAILY;UNTIL=20161111;WKST=SU";
calendarProvider.update(event);
and all functionalities in this library seem to work fine.
2- While reading pro-grammatically recurring events that have a specific UNTIL date in it's rRule , i have realized that also a field in the google event called "lastDate" is updated with one hour later after the UNTIL value ,so do i have to update also this field while updating the UNTIL value in the rRule?
The problem was with the library ,
calendarProvider.update(event);
does not seems to work with all event fields!

Display upcoming Calendar Events in Android Wear Watchface?

I want to show calendar events (daily agenda) from specific calendars on an Android Wear watchface.
Is the Calendar Provider available for query in an Android Wear Watchface?
How do I make sure it stays in sync throughout the day?
Depends on what info you need to look up. See WearableCalendarContract (though I don't think they've posted the JavaDocs yet, so I've only found a little info here). I'm able to, for example, get a range of event instances with this:
long begin = _time.toMillis(false);
Uri.Builder builder = WearableCalendarContract.Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, begin);
ContentUris.appendId(builder, begin + DateUtils.DAY_IN_MILLIS);
Uri instURI = builder.build();
Cursor cursor = getContentResolver().query(instURI, INSTANCE_PROJECTION, null, null, null);
But my attempts at reading the event table to find out more about the instances haven't worked (note that the WearableCalendarContract doesn't include an Events URI). I've tried both authorities to no avail.
AFAIK, the content provider is not available. Take a look into how to sync data in here: http://developer.android.com/training/wearables/data-layer/index.html

Categories

Resources