I need to read the events from a specific google calendar (I have a few on my phone) and list them date wise.
Searching our Forum I found Don's very good library and explanation,
www.b4x.com
I assume this is the way to go in current version.
I got error in B4XPages, may be I made some mistake somewhere, so I tried Activity logic, as the explanation is based on it.
I copy pasted the codes as explained but still got error.
Error log
I think I need to change some string value but do not know which one.
Please help.
Regards,
Anand
Searching our Forum I found Don's very good library and explanation,
Working with Calendars using ContentResolver (Query, Insert, Update, Delete)
Hello, i“m playing around with the Calendars on my Device and want to Query them. I found out how it works using ContentResolver querying the ContentProvider available in Android. You can find it documented here. I started using java code and a java-librarywrapper for this but then i realized...

I assume this is the way to go in current version.
I got error in B4XPages, may be I made some mistake somewhere, so I tried Activity logic, as the explanation is based on it.
I copy pasted the codes as explained but still got error.
B4X:
Sub Activity_Create(FirstTime As Boolean)
canAccessCal = False
Activity.LoadLayout("Layout")
Starter.rp.CheckAndRequest("android.permission.READ_CALENDAR")
wait for Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
Log("NO Permission READ Calendar")
Else
Starter.rp.CheckAndRequest("android.permission.WRITE_CALENDAR")
wait for Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
canAccessCal = True
cr.Initialize("CR")
End If
End If
If canAccessCal Then
' We are working from here now...
Log("can read write calendar")
Dim projection() As String = Array As String(ccon.ID,ccon.NAME,ccon.CALENDAR_DISPLAY_NAME,ccon.ACCOUNT_NAME,ccon.ACCOUNT_TYPE,ccon.OWNER_ACCOUNT)
cr.QueryAsync(ccon.CONTENT_URI,projection, ccon.VISIBLE&"=1",Null,ccon.ID&" ASC")
wait for CR_QueryCompleted(Success As Boolean, Crsr As Cursor)
Log($"QueryCompleted(${Success})"$)
If Crsr.IsInitialized Then
If Crsr.RowCount > 0 Then
Dim Cursor As Cursor
Cursor = Crsr
For i = 0 To Cursor.RowCount - 1
Cursor.Position = i
'calcon.ACCOUNT_TYPE,calcon.OWNER_ACCOUNT)
Log($"CR --------------------------------------"$)
Log(Cursor.GetString(ccon.ID)) ' You can use the constants you used for the projection. But remember: only the ones you defined in the projection are available in the Result.
Log(Cursor.GetString(ccon.NAME))
Log(Cursor.GetString(ccon.CALENDAR_DISPLAY_NAME))
Log(Cursor.GetString(ccon.ACCOUNT_NAME))
Log(Cursor.GetString(ccon.ACCOUNT_TYPE))
Log(Cursor.GetString(ccon.OWNER_ACCOUNT))
Next
Cursor.Close
Else
' No rows
End If
Else
'
End If
End If
End Sub
Error log
B4X:
Logger connected to: Xiaomi Redmi 4
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
can read write calendar
QueryCompleted(true)
CR --------------------------------------
1
main$ResumableSub_Activity_Createresume (java line: 556)
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at anywheresoftware.b4a.BA.addLogPrefix(BA.java:604)
at anywheresoftware.b4a.keywords.Common.LogImpl(Common.java:191)
at b4a.GCalenadar.main$ResumableSub_Activity_Create.resume(main.java:556)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
I think I need to change some string value but do not know which one.
Please help.
Regards,
Anand