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.

I looked for a good birthday widget in my Mac OS that would alert me for upcoming birthdays. It took me awhile to find the one I want and out of the others out there, I’d say Oliver Fornio’s Happy Birthday Widget is just what I needed. The UI display is simple, clean and tidy. The widget simply looks in your address book for birthday entries and lists them in the widget display. You can set the name display to either nickname or full name. The display shows how many days till your friend’s birthday comes and how old your friend will be. Just download the link here and double click the widget and press the install button then your widget will be automatically placed in your dashboard.

Related Posts Plugin for WordPress, Blogger...