Incorrect link to the contact table from the sms folder

I am trying to find contact details matching sms from sms phone mail. In my opinion, a column personis a foreign key of a column _id ContactsContract.Contacts.

My problem is that I am getting the wrong values ​​for the value personfrom the sms request. Some identifiers persondo not exist in the contact table, and some indicate completely different contacts.

Below is the code that I use to get a list of values person. Can someone tell me that I missed something or ran into a similar problem.

Tested with Nexus S running Android 4.1.2

Uri parsedUri = Uri.parse("content://sms/inbox");
    String[] projection = new String[] { "_id", "address", "person" };
    Cursor cursor = contentResolver.query(parsedUri, projection, null, null, null);

    Log.d(TAG, "Total Count " + cursor.getCount());

    if (cursor.getCount() > 0) {
        // String address;
        int person;
        int personIndex = cursor.getColumnIndex("person");
        if (cursor.moveToFirst())
            do {
                person = cursor.getInt(personIndex);
                if (person > 0) {
                    // Add this id to a list
                }
            } while (cursor.moveToNext());
    }
    cursor.close();

: Android Developer Portal (http://developer.android.com/guide/topics/providers/contacts-provider.html), , person, sms inbox ContactsContract.RawContacts ContactsContract.Contacts, .

+5
2

, person sms RawContacts. RawContacts, contact_id Contacts .

, RawContacts.

long contactId = 0;
Uri uri = ContactsContract.RawContacts.CONTENT_URI;
String[] projection = new String[] { ContactsContract.RawContacts._ID, ContactsContract.RawContacts.CONTACT_ID };
Cursor cursor = contentResolver.query(uri, projection, 
        ContactsContract.RawContacts._ID + " = ?",
        new String[] { rawContactId }, null);

if (cursor.moveToFirst()) {
    int contactIdIndex = cursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID);
    contactId = cursor.getLong(contactIdIndex);
}
cursor.close();

, sms Android. , sms , -, , , Android.

+5

, . , .

Cursor cursor=managedQuery(uri, null, null, null, null);

                    while (cursor.moveToNext()) { 
                        String contactId = cursor.getString(cursor.getColumnIndex( 
                                ContactsContract.Contacts._ID)); 
                        String hasPhone = cursor.getString(cursor.getColumnIndex( 
                                ContactsContract.Contacts.HAS_PHONE_NUMBER)); 
                        if (Boolean.parseBoolean(hasPhone)) { 
                            // You know have the number so now query it like this
                            Cursor phones = getContentResolver().query( 
                                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
                                    null, 
                                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, 
                                    null, null); 
                            while (phones.moveToNext()) { 
                                String phoneNumber = phones.getString( 
                                        phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));              
                            } 
                            phones.close(); 
                        } 
                    }
0

All Articles