Add a calendar on Android - 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.

Related

Querying firebase, without duplication

I am new to coding and I am just playing around to build an app where everyone can post new events. So I have already created notes like "user" and "events". The problem I face off is that I dont know how to avoid duplication like for example if two users are posting the excat same event.
I don't want to show them twice in my RecyclerView.
So I have to compare the date, the location and the description, due to this many queries, is the Firebase Realtimedatabase the right "tool"? Or should I use another software.
------/Events
---------/LbwXYVICCl9xd5m..
--------------datum: 10.04.2019
--------------userid: OncDIQis...
--------------location:New York
--------------description:Coldplay
You seem to define two events as being the same based on some of their properties having the same value. In a scenario like that, I'd use those combined properties as the key of the event.
So if you say that two events are the same if they have the same date, location, and description, then you can create the unique key of that event as ${date}_${location}_${description}. For example:
20190410_New York_Coldplay
I've put the date in an easier to search for format, which also filters the .s (since those are not allowed in keys. Now you can store the event under that key:
Events
20190410_New York_Coldplay
datum: 10.04.2019
userid: OncDIQis...
location:New York
description:Coldplay
With the above structure, if another user tries to create an equivalent event, it will get the same key.
Firebase Real-time database is the right tool for you as it updates the database in real time.
At the time of fetching the data from the firebase, you can check whether it is already present in your local database(where you are collecting data fetched from the firebase) or not.
I hope this will help you out.

How to get reminders list programmatically?

I created an Android app that read all the events of the calendar, it's work fine but I can't read the list of reminders: the simplified event in the Google calendar identified by this icon (knot on the finger)
Google Calendar Reminder
Someone can tell me how can I read this type of event or where can I find a tutorial or a guide where this is explained?
If you want to fetch list of reminders, use Events.list. It returns events and the accompanying reminders.
Default reminders
Default reminders are also returned when
doing an Events list query.
I discovered that the reminders aren't only on calendar but are in different Google app (keep for example).
Unfortunately it's not possible to access a this kind of data.
This the link of the answer in Stackoverflow: How to read reminders in google calendars
According to OferR The Reminders data is held in a database and accessible by the 'com.google.android.gms.reminders.provider.RemindersProvider' content provider.
So, the provider is not exported and therefore is not accessible to third party apps.

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.

Delete app inserted calendar event in android

I know how to delete and insert event in Android.
But the problem is that how can I delete the calendar event inserted by my own app.
Do I need to store all the event_id of the events inserted by my app?
But it seems it is not reliable, right? The event_id may be already become the id of other events. For example, user may manually delete the event that my app inserted and insert their own event which may have the same event_id.
Thank You.
One solution I can think of is using one of the fields to carry some kind of tag unique to your app. Like, in description you could have #MyBooksApp and then search events by that tag.
Of course, user can manually modify the event and it'll not get found but there's no way to work around that, obviously.
Another approach may be to store copy of the event or hash of name and description internally and check whether it's the same event using the hash prior to deleting.

sync custom events to default phone calendar in android

i have an application in which i need to sync the events that i get from an xml to the default calendar provided in the users phone.
for the above i have referred this tutorial.But over here the first it is required to get the id and name of all the available calendars in the users phone... i don't know the id and name of the default calendar in the users phone....which calendar should i use to put events in?
i am not putting the code here as the code is present in the link given.
thank you in advance.
You can't know ahead of time. There is no system setting for the default calendar. You must account for this in your application by allowing the user to select the calendar or coming up with your own way of determining the "default".
Be careful not to rely on the persistence of any calendar because if they are Google calendars they will come and go with corresponding changes in the cloud.

Categories

Resources