Share My Creation TBirdSync: Thunderbird contacts/calendar/tasks mirroring from PC to Android (sources included)

Background
I hesitated to post this as it's probably only useful for a small audience (if any), but as I didn't find another solution, perhaps it can benefit others who are looking for this or for something similar.

I've been using the excellent MyPhoneExplorer (https://www.fjsoft.at/en/) for years to sync my contacts, calendar, and tasks from a Windows PC (first MS Outlook, then Mozilla Thunderbird) to my Android devices. In the future (possibly distant - or even never) I may switch completely from Windows to Linux. Unfortunately I (and apparently anybody else) was unable to get MyPhoneExplorer running on Linux - e.g. with WINE - and I don't want the overhead of a VM.

So I decided to create something myself: TBirdSync. I haven't tested it on Linux yet - that's for later (or never). Tested on Windows 10 and Linux Mint 20.02 Cinnamon.

The big picture - my setup
TBirdSync.png


What does/doesn't it do?
It DOES:
- Synchronise Thunderbird contacts with one or more Android devices; contact matching is based on the combination of first and last name (which means that these combinations must be unique)
- Prepare calendar and tasks data and send them to the Android device(s) where they can be processed with the ICSx5 app (see below)
- Convert tasks data to calendar data, which means no separate tasks app is needed on the Android device: everything winds up in the calendar app, where tasks' titles are prefixed with '(T)' so that it's easy to distinguish them from appointments

It DOES NOT:
Perform a 2-way sync (so it's actually more mirroring than syncing): the synchronisation source is Thunderbird, and all changes to the data are expected to be applied there. Changes made on the Android device are not detected.

If you can live with these limitations, read on.

Why ICSx5?
I didn't want to write the calendar/tasks sync code as TBirdSync is a means to an end (i.e. moving to Linux) and not a goal by itself. Calendars are complex beasts and ICSx5 (https://play.google.com/store/apps/details?id=at.bitfire.icsdroid) is a low-cost app (1.99 EUR) that works perfectly; it's even open source and can be found on GitLab (https://gitlab.com/bitfireAT/icsx5). Among other, it syncs an iCalendar (.ics) file with a read-only calendar that it creates itself.

At the moment, ICSx5's sync can't be started via an Intent: on the Android device, TBirdSync starts the app and then a 'pull to refresh' is needed to sync the calendar and tasks data (unless a scheduled sync is setup; sync intervals as of 5 minutes can be selected). I've asked the developers if they would be willing to provide an Intent, and it's on their todo list. Once it's there, I'll update the app to start the sync without user interaction.

If you only want to sync contacts, ICSx5 is not needed.

Getting started
- Get ICSx5 (see above) and install it on the Android device(s)
- Install the TBirdSync app on the Android device(s), enter the settings, and save them
- Install the B4J program on the PC(s), enter the settings, and save them
- In the Android device(s) Settings / Battery / Battery optimization you may want to set TBirdSync and ICSx5 as 'Not optimised' so that they'll also keep going when the device is locked
- TBirdSync uses an iCalendar (.ics) file to process calendar and tasks data. In Thunderbird, you'll either have to manually use 'Export' from the 'Events and Tasks' menu each time you want to sync the data, or do this:
1. Export Events and Tasks to an .ics file
2. File / Open / Calendar file, and then select that exported file, and work with that calendar (and perhaps also delete the original one to avoid confusion/mistakes)
This way, the data are always available in .ics format. It does however slow editing calendar and tasks down a little, but in my opinion the performance hit is reasonable.

Other
- Deleting contacts (which is also used to update them as this simplified the code and speeds things up on the Android side because the PC side does the heavy lifting) didn't work on my Fire tablet with Android 5.1.1 but did on a Moto X Style phone with Android 7, which is why the minSdkVersion in the Manifest was set to 24 to correspond with Android 7. It is however possible that this was caused by the custom ROM I had installed on the Fire tablet and that it does work on older Android versions.
- The icon comes from https://www.pngrepo.com/svg/156939/update-business-user
- My environment: Windows 10, Thunderbird 78.10.1 (32-bit), Android 7, ICSx5 1.9.1-gplay, B4A 10.70, B4J 8.90

Non-core library dependencies
B4A:
- AndroidResources: https://www.b4x.com/android/forum/threads/16847
- Archiver: https://www.b4x.com/android/forum/threads/21688
- Clipboard: https://www.b4x.com/android/forum/threads/clipboard-library.7382

B4J:
- jReflection: https://www.b4x.com/android/forum/threads/jreflection-library.35448/

Screenshots

TBirdSync B4J screenshot.PNG
TBirdSync B4A screenshot.jpg


Enjoy!
 

Attachments

  • TBirdSync_B4A.zip
    96.9 KB · Views: 49
  • TBirdSync_B4J.zip
    63.9 KB · Views: 49
  • TBirdSync B4J screenshot.PNG
    TBirdSync B4J screenshot.PNG
    38.9 KB · Views: 145
  • TBirdSync B4A screenshot.jpg
    TBirdSync B4A screenshot.jpg
    294.8 KB · Views: 147
  • TBirdSync_B4A v2.zip
    98.9 KB · Views: 34
  • TBirdSync_B4J v2.zip
    65.5 KB · Views: 38
Last edited:

walt61

Active Member
Licensed User
Version 2 attached to the first post.

B4J changes:
- streamlined Msgbox2Async handling
- added button 'Select .ics copy folder' (and the label beside it); on Android 11, I couldn't find a directory that would be accessible by both TBirdSync and ICSx5; with this button, a copy of the calendar/tasks .ics file can be placed e.g. on a shared NAS folder and then be accessed with ICSx5 through a http subscription
- if an error occurs during sync preps, the connection with the server will now be closed
- at the first contacts sync (or after using menu option 'Reset contacts' on the Android device), an attempt will be made to delete all existing contacts on the Android device (after user approval)

B4A changes:
- streamlined Msgbox2Async handling
- added checkboxes 'Start at boot' and 'Keep alive'
- Manifest: changed targetSdkVersion from 29 to 30
- Manifest: added WRITE_EXTERNAL_STORAGE (for RuntimePermissions/GetSafeDirDefaultExternal)
- Manifest: added '<queries>' block to be able to detect the presence of ICSx5 (at.bitfire.icsdroid) on Android 11
- corrected RuntimePermissions handling
- at the first contacts sync (or after using menu option 'Reset contacts' on the Android device), an attempt will be made to delete all existing contacts on the Android device (after user approval)
 
Top