Posted 2010-09-14 17:20:00 GMT
When I show people an android phone, they tend to call it a fake iPhone and then become impressed by some feature. Besides being cooler than a me-too device, the platform is relatively open to being fiddled with.
A case in point of this is the contacts database: it's stored at /data/com.android.providers.contacts/databases/contacts2.db and you can read it with adb or with unyaffs from a nandroid backup. The database contains Facebook contacts and contacts attached to Google accounts (and the phone account if that's enabled). Facebook tries to stop you retrieving your data from it — this is one way to convert your Facebook friends to a vcard.
My phone was pick-pocketed in Hong Kong (it was quickly shipped out to a place called Po Lam and turned off). I have a nandroid backup of the contacts database and would like to feed it into a new phone -- the Facebook for Android is rather sticky about letting you "modify" a Facebook contact to add a number or something to it, so it would be rather fine to move Facebook contacts into normal contacts.
Using the sqlite3 program you can easily look at it. Among items of interest is the phone_lookup table which has a mapping of phone number to contact, with the phone number written backwards - like 144000949744+ for +447949000441. This is useful because caller id often comes up as 07949000441, with a different prefix and to look it up you probably do best by finding the longest match. There are additionally numerous useful "views" defined (queries that can to a certain extent be treated as tables).
Phone numbers and emails and things are stored in the
table (marked by mimetypes), and things are related by raw_contact_id:
for example, to fetch phone numbers use
select raw_contact_id,data1 from data where mimetype_id=(SELECT _id FROM mimetypes where mimetype='vnd.android.cursor.item/phone_v2')
and to relate names to id
SELECT _id,display_name FROM raw_contacts
I wished to preserve the following information for each contact: name, telephone numbers, email addresses, and physical addresses. Additionally, as my contacts have been collected from all sorts of different places, if any of the email addresses intersect, or the last eight digits of the phone number intersect, or the names intersect then the contacts should be merged intelligently (generally taking the longest of any field which matches sufficiently).
After a bit of fiddling, I came up with a grubby little Ruby program that takes a contacts2.db and prints out a vcard.
Thanks again Android!
Post a comment