Get Age Of Contact In Android

There is no shortcut in getting a contact’s age in Android. What I did instead was to get the birthday of the contact (if any is provided) and subtracted that from the current year.

The output of a contact’s birthday is a string formatted date with dashes (-) so I had to make a helper method to parse it; get the month, date and year; convert it to a Date object, then do calculation to get the age of the contact.

Check out the helper method below.

And this is how I retrieved the birthday of the contact from the contact list. Once retrieved, I parsed the output and passed it to the calculateAge() method.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *