Android Question Calendars: need some advice

JordiCP

Expert
Licensed User
Longtime User
I've never worked with calendars from a programmer's point of view up to now, so it all sounds quite new to me.

After exploring a bit in the forum, I see (may have missed others) the Calendar2 library and also @DonManfred's Tutorial. Both seem right tools for calendar management. But before going deep into them or post the exact same question in each corresponding thread, I think I need a more general vision about what can be done with calendars...


My exact need is to 'upgrade' a local calendar that is contained in a bigger app, and uses its own UI and database. It needs to be synchronised with Google Calendar, so that events are propagated to the different user's devices, but with the following restrictions:
  1. Keep the existing app UI for adding/deleting events, and synchronise them with Google Calendar --> I think this part is possible.
  2. Also keep the alert UI, generated by a service in the same app --> I guess it is more tricky, so it would need the ability to somehow receive the event alerts as intents in the user's app and prevent Google Calendar to manage them?
, so my question is if both solutions are valid -taking into account compatibility with Android versions and those things- for such needs, specially (2), and/or there is any other important thing to consider...

Thanks in advance for any input.
:)
 

DonManfred

Expert
Licensed User
Longtime User
My exact need is to 'upgrade' a local calendar that is contained in a bigger app, and uses its own UI and database. It needs to be synchronised with Google Calendar
From this point i would suggest to use my Tutorial (ContentResolver) to read/write from/to the correct Calendar with the type of com.google
Keep the existing app UI for adding/deleting events, and synchronise them with Google Calendar --> I think this part is possible.
once you know the correct calendar-id (note that id is a LOCAL ID from the list of calendars. It may change if you add/ remove any Calendars.

But.
-You can read all Events from the Google Calendar with all Data -> Up to you to build a Calendar-UI by yourself.
- You can write new Events to this Calendar using your own Logic/UI using ContentResolver
Also keep the alert UI, generated by a service in the same app --> I guess it is more tricky, so it would need the ability to somehow receive the event alerts as intents in the user's app and prevent Google Calendar to manage them?
i don´t think that this is possible (programmatically deactive this option in the calendar app).
BUT you can check the alerttable and get infos about Alerts for an specific Event. You may implement the alert UI by yourself. If the default app shows an alert the app still will do. You can deactivate it in the Google Calendar app and do it yourself in your App/your UI.

The point is that you need to write your own logic to get Eventalerts. But you should be able to get the Alerts using contentResolver...
 
Last edited:
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Thanks for the detailed answer. Much appreciated!:)

It all makes sense and gives me a broader vision. The UI part already exists, so will explore into this direction.

Thanks again.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
It may change if you add/ remove any Calendars.
depending on how often the calendars on the device may change it can be useful to always check the calendarlist first and find the matching Calender to use.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
But you should be able to get the Alerts using contentResolver...
this may give you a quickstart



B4X:
    Dim rcon As RemindersConstants ' Library from the Tutorial needed
    Dim event As Int = 12345 ' Eventid of which you want to get the Reminders
   
    Dim projection() As String = Array As String(rcon.ID, rcon.EVENT_ID ,rcon.METHOD, rcon.MINUTES)
    Dim selection As String = $"${rcon.EVENT_ID}=?"$
    Dim selectionArgs() As String = Array As String(event)
    cr.QueryAsync(rcon.CONTENT_URI,projection, selection,selectionArgs,rcon.ID&" ASC")
    wait for CR_QueryCompleted(Success As Boolean, Crsr As Cursor)
    Log($"QueryCompleted(${Success})"$)
    If Success = False Then
        Log(LastException)
    End If
    If Crsr.IsInitialized Then
        If Crsr.RowCount > 0 Then
            Dim crsrreminder As Cursor
            crsrreminder = Crsr
            For i = 0 To crsrreminder.RowCount - 1
                crsrreminder.Position = i
                Dim methodid As Int = crsrreminder.GetInt(rcon.METHOD)
                Dim method As String = "unknown"
                Select methodid
                    Case 1
                        method = "Notify"
                    Case 2
                        method = "eMail"
                End Select
                Log($"ID: ${crsrreminder.GetString(rcon.ID)} / Method: ${method} / Minutes: ${crsrreminder.GetString(rcon.MINUTES)}"$)
            Next
            crsrreminder.Close
        Else
            ' No rows
        End If
    Else
        '
    End If

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
4689: 26.01.2019 11:30:00 test with reminder / /
lvEvents_ItemClick(25, 4689) ' Eventid 4689
QueryCompleted(true)
ID: 51 / Method: eMail / Minutes: 60
ID: 52 / Method: Notify / Minutes: 10
** Activity (main) Pause, UserClosed = false **
 
Upvote 0
Top