[Galaxy S III Q&A, Help & Troubleshooting] rryk:
This would better be located in Galaxy S III Android Development forum, but apparently I can't post there yet as I have fewer than 10 posts. Moderators, please move this to that forum.

I am a new developer to Android. I wrote a simple program that tries to figure out which contacts are most called to. The program works just fine on the emulator, but fails to work on my Samsung S3. Specifically, I can not read the list of phone numbers of a particular contact. What I see is that ContactsContract.Contact._ID does not correspond to the ContactsContract.Data.RAW_CONTACT_ID. For example, I have a contact in my phone called "Mailbox abhören" ("voice mail"), which has a phone number +491793000333. In the ContactsContract.Contact I see two relevant entries (dumped using this code: http://tny.cz/95e6124e):

_ID = 1087
LOOKUP_KEY = 4063i27e12adb8d7365fe
DISPLAY_NAME = Mailbox abhören
DISPLAY_NAME_PRIMARY = Mailbox abhören
PHOTO_ID = null
PHOTO_URI = null
PHOTO_THUMBNAIL_URI = null
IN_VISIBLE_GROUP = 1
HAS_PHONE_NUMBER = 1
TIMES_CONTACTED = 0
LAST_TIME_CONTACTED = 0
STARRED = 0
CUSTOM_RINGTONE = null
SEND_TO_VOICEMAIL = 0
CONTACT_PRESENCE = null
CONTACT_STATUS = null
CONTACT_STATUS_TIMESTAMP = null
CONTACT_STATUS_RES_PACKAGE = null
CONTACT_STATUS_LABEL = null
CONTACT_STATUS_ICON = null

_ID = 3098
LOOKUP_KEY = 298i1
DISPLAY_NAME = Mailbox abhören
DISPLAY_NAME_PRIMARY = Mailbox abhören
PHOTO_ID = null
PHOTO_URI = null
PHOTO_THUMBNAIL_URI = null
IN_VISIBLE_GROUP = 1
HAS_PHONE_NUMBER = 1
TIMES_CONTACTED = 0
LAST_TIME_CONTACTED = 0
STARRED = 0
CUSTOM_RINGTONE = null
SEND_TO_VOICEMAIL = 0
CONTACT_PRESENCE = null
CONTACT_STATUS = null
CONTACT_STATUS_TIMESTAMP = null
CONTACT_STATUS_RES_PACKAGE = null
CONTACT_STATUS_LABEL = null
CONTACT_STATUS_ICON = null

However, in the ContactsContract.Data, the entries for these two contacts are completely irrelevant and point to some other contact (real names and addresses obfuscated, dumped using http://tny.cz/afef6836):

id = 6985
mimeType = vnd.android.cursor.item/photo
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 0
data1 = null
data2 = null
data3 = null
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = https://www.google.com/m8/feeds/photos/media/xxx@yyy.com/zzz
sync2 = null
sync3 = null
sync4 = 0

id = 6986
mimeType = vnd.android.cursor.item/name
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = Someone Private
data2 = Someone
data3 = Private
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = 1
data11 = 0
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11

id = 6987
mimeType = vnd.android.cursor.item/note
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 =

data2 = null
data3 = null
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11

id = 6988
mimeType = vnd.android.cursor.item/nickname
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = null
data2 = null
data3 = null
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11

id = 6989
mimeType = vnd.com.google.cursor.item/contact_misc
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = null
data2 = null
data3 = null
data4 = null
data5 = null
data6 = null
data7 = null
data8 = 4
data9 = 5
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11

id = 6990
mimeType = vnd.android.cursor.item/group_membership
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = 5
data2 = null
data3 = null
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11

id = 6991
mimeType = vnd.android.cursor.item/phone_v2
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = +380975356308
data2 = 2
data3 = null
data4 = +380975356308
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11

id = 2340183
mimeType = vnd.android.cursor.item/name_svoice_dmetaphone_primary_encoding
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 0
data1 = SOMEONE PRIVATE
data2 = SOMEONE
data3 = PRIVATE
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = null

I've also tried dumping the whole ContactsContract.Data database and found entries with the expected number:

id = 118113
mimeType = vnd.android.cursor.item/phone_v2
rawContactId = 3047
isPrimary = 1
isSuperPrimary = 0
dataVersion = 1
data1 = +491793000333
data2 = 2
data3 = null
data4 = +491793000333
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = null

id = 6969
mimeType = vnd.android.cursor.item/phone_v2
rawContactId = 1084
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = +491793000333
data2 = 2
data3 = null
data4 = +491793000333
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11

3047 does not exist. 1084 points closes the loop and points to the Someone Private:

_ID = 1084
LOOKUP_KEY = 4063i2a66cd210fc7ef2a
DISPLAY_NAME = Someone Private
DISPLAY_NAME_PRIMARY = Someone Private
PHOTO_ID = null
PHOTO_URI = null
PHOTO_THUMBNAIL_URI = null
IN_VISIBLE_GROUP = 1
HAS_PHONE_NUMBER = 1
TIMES_CONTACTED = 0
LAST_TIME_CONTACTED = 0
STARRED = 0
CUSTOM_RINGTONE = null
SEND_TO_VOICEMAIL = 0
CONTACT_PRESENCE = null
CONTACT_STATUS = null
CONTACT_STATUS_TIMESTAMP = null
CONTACT_STATUS_RES_PACKAGE = null
CONTACT_STATUS_LABEL = null
CONTACT_STATUS_ICON = null

I am confused. Is this some non-standard database used only by Samsung? My phone seems to work just fine with my voicemail and never calls Someone Private when I dial it. And when I dial Someone Private's number it is never identified as "Mailbox abhören".