I'm trying to build a conversation list for SMS messages. Therefore I'm reading "content://sms/conversations" and read the first few messages of each conversation to find the communication partners' phone numbers. With these numbers I try to retrieve the contact_id from ContactsContract.CommonDataKinds.Phone to fetch the rest of the person's information from the contacts database.
String[] returnVals = new String[] {ContactsContract.CommonDataKinds.Phone.CONTACT_ID};
Cursor pCur = thisContent.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
returnVals,
ContactsContract.CommonDataKinds.Phone.DATA1 + " = \"" + phoneNumber + "\"",
null,
null);
When I rotate through this query's results I see that some contacts weren't found, although they are stored in the contact database. For example, one number that is associated with one of my contact list and is located in the States that seems to be stored with dashes. I understand that this might be a problem, but other numbers I extracted from the threads are stored the way they appear in the text messages and still don't get found.
So my questions are:
- Is this the right approach? Am I missing something? Is there an easier way to achieve this?
- What I will get back from ContactsContract.CommonDataKinds.Phone is a reference to the _ID of the persons contact. I suppose I can't handle that like a proper long type _ID, but how do I need to do that?
- Is there a tutorial regarding SMS handling in Android besides the SDK's documentation in terms of surrounding tasks like this one?