Background
I'm trying to update contacts data and put there the birthdate of each.
The problem
It seems that for each device I try (and I didn't even try that many devices), the insertion has one or more of those issues:
- when viewing/editing the contact, the brithdate can't be clicked and edited.
- when viewing/editing the contact, the format that's shown isn't the same as the one that's shown when the user puts the birthdate
- Missing year, or totally wrong year.
- when viewing the contact, the birthdate isn't shown, yet when editing it, it is shown. Also, the opposite.
What I've tried
I've tried using a timestamp and a full ISO8601 format (because of this link, meaning it's "yyyy-MM-dd HH:mm:ss"). I've also tried "yyyy-MM-dd" and I tried using the default format of the date of the device.
All had the mentioned issues (at least one for each).
Here's a piece of the code:
final Date birthdate = ...
// String birthdateStr = new SimpleDateFormat("yyyy-MM-dd").format(birthdate);
// String birthdateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(birthdate);
// String birthdateStr = new SimpleDateFormat(((SimpleDateFormat) java.text.DateFormat.getDateInstance(java.text.DateFormat.DEFAULT, Locale.getDefault())).toLocalizedPattern(),Locale.getDefault()).format(birthdate);
String birthdateStr = Long.toString(birthdate.getTime()/1000);
final Builder builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
builder.withValue(Data.RAW_CONTACT_ID, ...)
.withValue(ContactsContract.Data.MIMETYPE, Event.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Event.START_DATE, birthdateStr)
.withValue(ContactsContract.CommonDataKinds.Event.TYPE,
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY);
Of course, I've also looked on this issue here, and found similar issues, but none of the proposed solutions seem to work well.
The question
How should I really insert a birthdate into the contacts? How come each device has its own way to interpret the dates? What's the correct standard to put the birthdate ?