Hey guys ?
I'm going to add a new calendar to the device's calendar database.
I read the following descriptions.
1-https://developer.android.com/guide/topics/providers/calendar-provider#kotlin
2-https://developer.android.com/reference/android/provider/CalendarContract
Finally, I found a way to add a new calendar to the database at this link
3-https://developer.android.com/reference/android/provider/CalendarContract.Calendars
I tried to write these codes with B4A
and
But B4A stops the program with an error
We see here that we have to do it with a " sync adapters " !!
Also in link number 3 (operation) we see that we have been told "All operations can be done either as an app or as a sync adapter. "
Please guide me how to use "sync adapters" for inserting a new calendar "
? ? Thanks ? ?
I'm going to add a new calendar to the device's calendar database.
I read the following descriptions.
1-https://developer.android.com/guide/topics/providers/calendar-provider#kotlin
2-https://developer.android.com/reference/android/provider/CalendarContract
Finally, I found a way to add a new calendar to the database at this link
3-https://developer.android.com/reference/android/provider/CalendarContract.Calendars
I tried to write these codes with B4A
B4X:
Sub Process_Globals
Dim G_CalendarConstants As CalendarConstants
Dim G_EventConstants As EventConstants
Dim G_AttendeesConstants As AttendeesConstants
Dim G_remindersConstants As RemindersConstants
Dim G_InstancesConstants As InstancesConstants
Private ContentResolver1 As ContentResolver
End Sub
and
B4X:
Sub make_new_calendar
'' https://developer.android.com/reference/android/provider/CalendarContract.Calendars
Dim ContentValues1 As ContentValues
ContentValues1.Initialize
ContentValues1.PutInteger(G_CalendarConstants.VISIBLE,1)
ContentValues1.PutString(G_CalendarConstants.ACCOUNT_NAME,"xxxxx@gmail.com")
ContentValues1.PutString(G_CalendarConstants.ACCOUNT_TYPE,"xxxxx.group")
ContentValues1.PutString(G_CalendarConstants.NAME,"Persian Calendar")
ContentValues1.PutString(G_CalendarConstants.CALENDAR_DISPLAY_NAME,"xxxxx Calendar")
ContentValues1.PutInteger(G_CalendarConstants.CALENDAR_COLOR,-3144201)
ContentValues1.PutInteger(G_CalendarConstants.CALENDAR_ACCESS_LEVEL,200)
ContentValues1.PutInteger(G_CalendarConstants.SYNC_EVENTS,1)
ContentValues1.PutString(G_CalendarConstants.CALENDAR_TIME_ZONE,"Asia/Tehran")
ContentValues1.PutString(G_CalendarConstants.ALLOWED_REMINDERS,"0,1,2")
ContentValues1.PutString(G_CalendarConstants.ALLOWED_AVAILABILITY,"0,1")
ContentValues1.PutString(G_CalendarConstants.ALLOWED_ATTENDEE_TYPES,"0,1,2")
ContentValues1.PutString(G_CalendarConstants.OWNER_ACCOUNT,"persiancalendar#persianevent@xxxx.groxxxxup.com")
Dim resUri As Uri = ContentResolver1.Insert(G_CalendarConstants.CONTENT_URI,ContentValues1)
Dim calenderID As Int = resUri.ParseId
Log($"calender id is: ${calenderID}"$)
End Sub
But B4A stops the program with an error
B4X:
Logger connected to: asus ASUS_X00LD
--------- beginning of main
** Service (starter) Destroy (ignored)**
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
We are working from here now...
Error occurred on line: 182 (Main)
java.lang.IllegalArgumentException: Only sync adapters may write to account_name
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
at android.content.ContentResolver.insert(ContentResolver.java:1557)
at anywheresoftware.b4a.objects.ContentResolverWrapper.Insert(ContentResolverWrapper.java:75)
at calcaltest.example.main._make_new_calendar(main.java:1311)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:169)
at android.app.ActivityThread.main(ActivityThread.java:6521)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
We see here that we have to do it with a " sync adapters " !!
Also in link number 3 (operation) we see that we have been told "All operations can be done either as an app or as a sync adapter. "
Please guide me how to use "sync adapters" for inserting a new calendar "
? ? Thanks ? ?