0

I am trying to get the contact's display name from the sms uri. I should get the person's contact id if that person is in my contact list. But every time I got a Null as a respond which means the person is not in my contact list. But actually the person is in my contact list and shown in the message. So is there a way to get the person's display name from sms uri?btw, I am using 2.2 emulator.

user449110
  • 81
  • 1
  • 3
  • 7

1 Answers1

3
Uri personUri = Uri.withAppendedPath( ContactsContract.PhoneLookup.CONTENT_FILTER_URI, smsMsg.getOriginatingAddress());  

cur = appContext.getContentResolver().query(personUri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null );  

if( cur.moveToFirst() ) {  
             int nameIndex = cur.getColumnIndex(PhoneLookup.DISPLAY_NAME);  

             PersonName = cur.getString(nameIndex); 
}
cur.close();
Varundroid
  • 9,135
  • 14
  • 63
  • 93
  • This works great, but not on some 4.0.3 device? please kindly tell me if you confront similar problem: http://stackoverflow.com/questions/12065606/getcontentresolver-query-cause-cursorwrapperinner-warning – thecr0w Aug 22 '12 at 03:13
  • Thanks. :) It is working. I tested it on 2.2, 2.3 and 4.0.3 and it is working great. :) – androidEnthusiast Sep 11 '12 at 21:34