Android Question Calendars: need some advice

Discussion in 'Android Questions' started by JordiCP, Jan 25, 2019.

Tags:
  1. JordiCP

    JordiCP Well-Known Member Licensed 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.
    :)
     
  2. DonManfred

    DonManfred Expert Licensed User

    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
    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
    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: Jan 25, 2019
    KMatle, BillMeyer and JordiCP like this.
  3. JordiCP

    JordiCP Well-Known Member Licensed 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.
     
  4. DonManfred

    DonManfred Expert Licensed User

    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.
     
    JordiCP and BillMeyer like this.
  5. DonManfred

    DonManfred Expert Licensed User

    this may give you a quickstart



    Code:
    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
     
    JordiCP likes this.
  6. DonManfred

    DonManfred Expert Licensed User

    Added the above snippet to the Tutorial
     
    KMatle likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice