Syncronizing contacts and calendars with your own server, on Android #android
I just spent 2½ hours making my new Android phone sync using DAVdroid to radiCALe on my home server.
It took a while, because there are a couple of things you simply "have to know":
- To communicate encrypted, the certificate must be trusted by your phone. If you have opted out of the CA-mafia and created your own, self-signed CA certificate, this means having to have a pin, pattern or password on your lock screen, and a constant warning about your network being monitored. Pointing the browser on your phone at your ca.crt file will import the certificate easily enough, though.
- You need to configure radiCALe to use your certificate and remember to turn on SSL.
- You must remember to use the correct type of htpasswd-file for authentication (if that is what you choose); it must match radiCALe's config.
- You must place your addressbook.vcf in /var/lib/radicale/collections/USERNAME/addressbook.vcf/addressbook.vcf - yes, it looks like a directory too much.
- You must place your calendar files in /var/lib/radicale/collections/USERNAME/calendar.ics/ - all of them. Otherwise DAVdroid/radiCALe will only show one of them. You can't place your other calendars in another subdir, they won't show up in DAVdroid.
- Use https://example.org:5232/USERNAME/ as the path to your server in DAVdroid.
- If the phone says there is a temporary syncronization problem with your contacts, try adding a new contact to the DAVdroid account. When I did that, sync pulled in all the contacts.
I am only sync'ing my web-based calender on the server in one direction (server to phone); this seems to just work. Addressbook will probably only be in the other direction (phone to server).
I managed to avoid sending my contacts to Google, by turning off all sync before creating the Google account (this is done in Settings/Data Usage top right menu "Auto-sync data"). After creating the account, I turned off wi-fi and mobile data - and then I reenabled Auto-sync data, and went to Settings/Accounts/Google and disabled sync for everything Google there. After that I could enable mobile data and wi-fi again.
The point here is for the email app to update Auto-sync data must be on, but if I turned it on again while there was a network connection available, my contacts would have been synced to the new Google account before I could disable syncing to it - thus the turn off wi-fi and mobile data "trick".
Phew.
Update: If you try setting up a DAVdroid account, and you get an "HTTP error: 500 internal server error", while radiCALe reports no problem in the log, double check the permissions/ownership of the files in /var/lib/radicale/collections/ For some reason one of the .props-files got root.root as owner.group, changing to radicale.radicale fixed the problem.
Also, if DAVdoid says there is in intermittent problem with syncing your calendars, check that your .ics-files have UID entries for all VEVENTS - they are apparently mandatory for DAVdroid. ⊗
Comments
Thanks for the comments!
Android exports all contacts to one file so I didn't even think of splitting them, and most calendars I have seen also export many events to one VCALENDAR file - but it is nice to get an idea of why the "quirks" I observed might be.
UID: Ok, I have been to lazy to read the specs, I just went with how stuff looks in the real world, which is always risky (as is just going by the spec, of course :-)).
Are you saying the spec is the to to have each event as a separate file?
Nice to read that people set up their own servers and use DAVdroid :-)
Some additions: 1) For Radicale, all contacts are expected to be in the directory addressbook.vcf – one per file, so there's not a directory too much. Apparently, it also works when there are multiple contacts per file because Radicale is splitting the contacts itself. 2) The same applies to events: one event per file is expected. That's how CalDAV works: each event is accessible (for reading, updating etc.) as a single resource (Radicale may split up the file to multiple virtual files like for the address book, but apparently it doesn't). Also, by the CalDAV spec, all members must be direct children of the collection. 3) Also, by iCalendar RFC, all VEVENTs, VTODOs, VJOURNALs and VFREEBUSYs MUST contain a UID to uniquely identify the entry (like DAVdroid does).
- rfc2822