I'm trying to update contacts data and put there the birthdate of each.
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:
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.
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 ?
Open the Google Contacts app on your smartphone. Now, search for the contact in which you want to add a birthday. Click on the Edit button (Pencil icon) at the top right corner. Now, tap the 'More fields' option at the bottom and look for the birthday option.
The standard Android phone app date field can be used for birthdays. So, go into your phone app, the one with the blue phone icon, select the contacts tab on top. Then select a contact. Then select the edit icon (a pencil.
Based on this answer, I would say that you should use the format YYYY-MM-DD, but you need to define a account type and account name. So add those lines:
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
Let me know if this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With