Insert new calendar from SyncAdapter in Android - 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.

Related

Providing calendar data for the Calendar app

In the Android calendar app one can activate certain calendars, like holidays or birthdays. In the case of holidays I suppose the data comes from Google, in the case of birthdays the data comes from my contacts.
I would like my app to provide such calendar data. The data would be generated by my app, the Calendar app would simply display it. I would like my app to show up among the aforementioned list of calendars in the Calendar app, like holidays and birthdays, where the user may activate it and choose a color.
To make things clear: I don't want my app to access the Calendar app, but the other way around: the Calendar app would access the calendar data provided by my app.
Is this possible in the way I describe? What API do I have to implement?
If this is not possible this way, is there another way that comes close to what I'm describing?
Or is the only way to provide data to the Calendar to ask write permission for the Calendar and add events?

How to query new Android Calendar App Reminders?

Last month Google Added the ability to add standalone Reminders into their Calendar app (see article), i have tried to get those events through the standard Calendar Content provider but without any success, those items are not returned by the CalendarContract.Instances.CONTENT_URI query and also are not listed as alerts in the CalendarContract.CalendarAlerts.CONTENT_URI.
Maybe this data is not exported at all.
P.S. I know how to query reminders associated to events, this is not what i am asking here

Android Calendar Provider Sync - SYNC_DATA columns?

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.

Calendar Backup and Restore

I am building a application which takes a backup of calendar & restores it on demand.
How can I achieve this in Android? Are there any api's which imports/exports contacts just like for Contacts ?
Once you've got all the data you would like to put back into the calendar, you can use the google-api-java-client to access the users google calendar and put your events in it. Here's an example of using it in android.

Is there a way to get notified when a user adds a new calendar entry

Can i get informed in my android application when a user adds a new entry in his calendar application (i.e. via listeners, ...) or is checking the calendar every now and then via the content provider of the calendar app the only solution to find out if the user has added new entries ?
Can i get informed in my android
application when a user adds a new
entry in his calendar application
(i.e. via listeners, ...)
There is no calendar application in the Android SDK. There is a calendar application in the open source project, but it may or may not exist on any given device, since device manufacturers are welcome to replace it. It is also possible that the user will download an alternative calendar application that replaces the built-in one.
is checking the calendar every now and
then via the content provider of the
calendar app the only solution to find
out if the user has added new entries
?
There is no calendar content provider in the Android SDK. There is a content provider used by the calendar application in the open source project, but see above for the issues with relying upon that application. Also, the core Android team wishes that you would not rely upon undocumented content providers.
If you wish to work with Google Calendar, please use the appropriate GData APIs, until and unless more calendar functionality is added to the SDK.

Categories

Resources