Android Calendar Provider Sync - SYNC_DATA columns? - android

I'd like to sync between the internal Android calendar and my application.
I'm using CalendarContract available from Android API 14 onwards.
Any change of the content provider "com.android.calendar" calls onPerformSync(..) of my sync adapter.
However, at this point, all the rows of the events are set DIRTY = 0.
That means, the Google calendar sync must have set the DIRTY FLAG to zero before my sync adapter can access them.
CalendarContract.EventsColumns.SYNC_DATA1 - SYNCDATA10 are said to be columns of the content provider for use with sync adapters.
Does anybody know if there is some convention for what is the use of these columns?
I've realized that on my device SYNC_DATA5 stores the date last modified and SYNC_DATA1 seems to store the Google event ID. So it seems whenever the Calendar app syncs with Google Calendar, these columns are modified.
However, if I choose to use one of these columns for my sync adapter, how can I make sure another application doesn't use the very same columns and they override each other?
If SYNC_DATA5 is ALWAYS used by Google Calendar to store the date last modified I would be fine with just using that for my sync logic, I just need to be certain that this is a convention.

The SYNC_DATA columns can be used for any value. I'm not sure on how the google calendar does that, but they are intended for stuff related to your sync adapter, applications not syncing the calendar must not use them. So you're safe to use any column (given you don't change it between versions of your application, or you'd have to write migration code), as there should not be any other sync adapters working on your calendar.
You can not rely on the SYNC_DATA columns when not being a sync adapter, do not use them when the calendar is not "yours".
However, I have a strong feeling you're not syncing properly. To sync a calendar, you must use a separate calendar, not any calendar synced by google or any other third party app. I'll also list some other steps involved which I think you performed, but may be helpful to others.
You also need to append some parameters to any of your requests for the system so you get access to the sync adapter fields. Also, you should sync your calendar from an AbstractThreadedSyncAdapter implementation only. For that, you also need to provide an authenticator, if you have none yet (so the user will be able to enable/disable your sync adapter in the sync preferences of an account). An overview on the sync adapter thing can be found in this blog post.
If you don't have server-side accounts and only one calendar, you need to do some stuff when starting up for the first time:
Create an account
Create the calendar bound to that account
Enable your Sync Adapter
After that, Android will take care of executing your sync adapter from time to time, and you can access the SYNC_DATA columns without collisions (in the calendar you created) and DIRTY flags are served properly.

Related

Android: Google Calendar API, public events for all users

I decided to use Google Calendar API for my running app. I need to have some default public events in my calendar, this way anybody who is logged with different Google accounts could see them.
The questions is, what is the easiest way to store events, that everybody, who is logged from different accounts could see them?Maybe I need to create main events calendar and share to other local calendars?
You may want to check the use of Extended Properties which makes it easy to store application-specific data for an event without having to utilize an external database.
You can have the shared properties which are visible and editable by all attendees of an event. This property is shown regardless of the calendarId used in the request.
And to add or update events, using patch requests is the preferred method, as it allows you to manipulate some properties while leaving others untouched. Adding a new property with the same key will overwrite any existing properties with the same key.
Please visit the given link for a more detailed information.

How to fetch tasks from android calendar?

I am working on calendar application and i search on this issue "how to get all tasks from android calendar not from google calendar" but i got that it is not possible to fetch tasks from the calendar.can anybody tell me is it true or false? in case of false please help me to getting tasks from calendar in android.
I am using inbuilt sPlanner not google calendar.
Tasks is not part of Calendar. However, you can use the Tasks API to accomplish this under the right circumstances.
By default, there's no identifier for whether or not a Task is associated with your Calendar or not. Two easy ways of creating such an identifier would be to either include some sort of key in the description or create a Task List exclusively for Calendar tasks.
If using a key, just retrieve all the tasks and pick only ones containing your key. If using an exclusive Task List, just list all the tasks from the specific list.
Also the calendar being on Android also should not matter here. The Android Calendar app just displays a Google Calendar.

Insert new calendar from SyncAdapter in Android

I'm facing some troubles with creating new calendar in Android. Here is my scenario:
I have app with account, also I have SyncAdapter which sync news etc., now I want to insert new calendar where I have new element to sync in Data and Synchronization where I can unchecked sync calendar (like in Google or Outlook account) and until I checked it again, I wouldn't see it in my calendar app.
Do you have any examples how to add Calendar in Data and Synchronization?
EDIT:
Ok, I know already how to add more options in Data and Synchronization menu, just define another provider contentAuthority in your_syncadapter.xml like:
android:contentAuthority="com.android.calendar"
But here I change ContentProvider for this SyncAdapter, what if I want to use different? Now i have NullPointerException because ContentProvider have nothing.

How to implement CalenderView in Android

I am new at android this, so this might sound a bit confusing..
i am making an app that requires to have calendars showing events in week, day and month views (like google calendar). I have implemented this is a testing version but i want to change the implementation to make it more flexible. currently the event are stored in database and are edited and used in various activities in the app. Can i have android manage the events in it's calendar? but i would still need to be able to manipulate it from the app and store extra info other than the time and date and description. These extra info will be used for calculations. We also need to have a calendar in the app. Can we retrieve the events specific to the app for doing all this?
This tutorial might be of help.

Add a calendar on Android

I'd like to add a new calendar for my application (to divide it from other events), as GMail does.
If there isn't a way to that, how could we delete our events from the calendar when the app is disinstalled?
Thanks in advance.
The contract for the calendars can be found here. However, you need the account name and type to be able to insert a new calendar. I'm guessing gmail can do this since it has your google account info - I'm not sure if your app will be able to do the same.
As for your second questions, here is the spec for calendar events. You will just need to know the _ID of the event in the DB to be able to remove it (which you should be able to get fairly easily).
Events can be deleted either by the _ID as an appended id on the Uri or using any standard selection. If an appended id is used a selection is not allowed. There are two versions of delete: as an app and as a sync adapter. An app delete will set the deleted column on an event and remove all instances of that event. A sync adapter delete will remove the event from the database and all associated data.

Categories

Resources