How to get deleted events on an Android calendar? - java

At the moment, I am working on a calendar SyncAdapter.
I had no problem in creating a new calendar associated with an existing account or creating event so this part is working fine.
I also achieved detecting new/modified events on the client side by using the DIRTY flag defined on CalendarContract.Events.
However, when it comes to deletion, I encounter a big difficulty:
When I suppress an event through the android calendar app, it seemingly do not just set the DELETED flag to 1 but actually completely removes the event.
Is there any way I can know when an event is deleted this way, since I need to inform the server about the event deletion ?
Thanks for you time and sorry for this clumsy first post on stackOverflow.

Well, I solved my problem:
The event is completely deleted by the calendar application in the case where you did not put a value in the CalendarContract.Events._SYNC_ID field of the event.
I hope it will maybe help someone else having the same problem.

Related

Which Android Classes can be used to enable an action for every event in a specific calendar?

I'm looking to see if this problem is feasible. I want to create an Android app that allows a user to enable Do Not Disturb for every event in user-specified calendars. I've already looked into the AlarmManager class, and it does not seem to work for this purpose. A single AlarmManager instance would work for one half of one event (turning Do Not Disturb On). Another AlarmManager instance would be required to turn Do Not Disturb off. This would have to repeat for every event (which is variable) in the specified calendars. Is there an easier approach to this, or am I looking at this problem all wrong? I know that this has been done in stock Android, but it only works for one calendar at a time. If there is a better solution to this, could you point me toward the proper Android SDK classes? I do not need a code example. Thanks.

Xamarin c# Loader example?

This problem is for Xamarin Android C# , but if someone can help in java I'm sure I can convert the code over ..
I'm trying to get some sort of automatic notification on a db that data has been inserted / deleted / etc.
There is outside apps that have access to the db in question, that insert / etc..
I've tried a file observer but it misses most of the inserts.
I've tried using content observer but it never fires a onchange
I've tried using the content observer inside a cursor but no onchange happens either.
(if I understand correctly they will only fire if I register a change occurred which is what I don't want)
Now I've discovered that loaders might be a solution..
They seem to have their own observer that fires when the data changes.
If this is also not an answer then perhaps a database trigger of some kind to notify my app the data was modified ?
I really need guidance here.. no idea how to properly implement a loader..
or if the content observer can be sufficient somehow with some sort of auto trigger as such..
OK, So!
The reason that file Observer was missing db inserts is because a SQLite DB is actually a 2 - 3 file object .. if you watch "Example.DB" then you can miss insert that can happen on Example.DB-shm or Example.DB-wal..
The fix to this, and its not a great fix, is to instead watch the folder ..
doing this will catch all inserts/deletes ..
The problem with this is that it will cause multiple OnChange() 's to execute..
So when coding a file observer like this, you have to either call the stopwatch() while you process the call and switch it on afterwards
OR
Have a "Global Variable" (C# guys are gonna swear at me for calling it that)
or static var
that lets the app know that you are already busy on the event so don't execute the code till the previous call has been completed ..

EWS and Exchange 2010 Streaming Notifications - Seeing double

I'm working on integrated an application with Exchange using EWS Java. Yes, it's not officially supported, I know. It's all pretty straightforward and I have streaming notifications set up with the exchange server. However, I've hit a couple of snags that are a bit head-scratching.
First, it seems that every event (or batch of events) gets sent twice. For example, if I'm watching the Calendar for Modified events and I create a new appointment or modify an appointment, I'll get two identical notifications, each with an ItemEvent and a FolderEvent. They're definitely distinct objects coming in one right after the other and there is zero difference between the two events. Each object has the same value in any relevant field as the previous. The only difference seems to be the memory address.
Second, I'm hoping to make the notifications a bit more fine-grained. I want to see when a calendar item has been modified, but not when a calendar item is created. It appears that I can only watch the Calendar folder overall and that Modified includes new items. Is there any way to make that more precise?
EDIT: Actually, I found that this only seems to happen with Meetings created in the Calendar folder, and only those with other Attendees. Two NotificationEventArgs, each with a FolderEvent and an ItemEvent. On further inspection, I recently found that one ItemEvent is Created and one is Modified, which isn't terribly surprising to me now knowing how Exchange tends to handle Appointments. The idea was to watch for both created and modified items, although I suppose it could have been broken up into two streaming subscriptions or, given the behavior, set to only modified as that would have captured "new" Appointments anyway.
In any case, this was handled with a periodic SyncFolder (Much was changed between the asking of this and the final design), which worked out well in the end.
Although I dont have experience of working on EWS in Java, Ill try to answer your questions as the concept remains the same. My code references will be from C#
For the first part, the behavior you are experiencing is the expected behavior. When you subscribe to a folder, you get notified on any event that you have specified while creating the subscription takes place. Thus if you have subscribed to the "Calendar" folder for Modified and Create events, and you create or modify an appointment, you will get 2 notifications:
1 for the Folder level changes (FolderEvent): even if you create a new item, the folder has actually been "modified"
1 for the Item level changes (ItemEvent): for the created item
These two are NOT same. They may look similar as both inherit from "NotificationEvent" base class, but are different types.
http://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.folderevent(v=exchg.80).aspx
http://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.itemevent(v=exchg.80).aspx
For the second part, to see only modified events, select only "EventType.Modified" when you are creating the subscription. It would be good if you can share your code snippet to show how you are subscribing.

How to update the alarm ringing time While updating calendar events?

I'm trying to set alarm for calendar events that are inserted through my application. I have also set alarm for events(i.e) when calendar event notification shows, Alarm also sounded. Now, if I update the event time, I must get the alarm time also be updated from old time to new time. How to make out this?
Any help is highly appreciated and Thanks in advance...
Does android have any 'foreign key' type relationship between Events and their Reminders in its calendar content provider? I think there it is, and can help you. The link below is from android calendar app's source, and it is related to edit event activity, used in editing and inserting events. in save() method, used in this class, you can find how android itself saves events, and stores them, I think it would help.
click to see android calendar src code

background process using thread

I want to continuously check a table in the database to see whether a new row has been added to it. This runs as a back ground process. I think a thread should be used for this task. but I have no idea how to write the code. Can somebody help me with this please?
Well, you're not really giving us much to go on here.
You might find it easier to use a database trigger, which will fire some code whenever a specified action occurs (e.g. insertion of new data). You will need to look up details for your specific database.
I just realised that you have probably already tried to use triggers and failed: sql trigger not work as expected. Either approach will work, but I would prefer keeping everything in the DB and avoiding external processes if possible.
What should happen if an insert occurs but your process has died for some reason?
Oracle can now communicate to Java via listener. So if you register for some event, your Java listener will receive that event from the database.

Categories