android - Load SMS conversation along with contact name -


i'm developing sms application , come following issue. can read sms conversation using provider telephony.sms.conversations using cursorloader. cursor returned cursorloader, can display conversations's address phone numbers.

my question how retrieve sms conversation contact name efficiently display along sms conversation, not phone number. there anyway load list of contacts list of phone numbers returned cursorloader before?. of course i've tried load 1 one contact name using phone number terribly reduce application performance.

thank in advance.

i've been searching solution myself , came out compromise in opinion.

as query finished, store in hashmap<string, string> contact_map values as

int sender_address = cursor.getcolumnindex(telephony.textbasedsmscolumns.address);  while (cursor.movetonext()) {                 contact_map.put(                         cursor.getstring(sender_address),                         getcontactname(getapplicationcontext(), cursor.getstring(sender_address))                 );             } 

method getcontactname:

public static string getcontactname(context context, string phonenumber) {     contentresolver cr = context.getcontentresolver();     uri uri = uri.withappendedpath(contactscontract.phonelookup.content_filter_uri, uri.encode(phonenumber));     cursor cursor = cr.query(uri, new string[]{contactscontract.phonelookup.display_name}, null, null, null);     if (cursor == null) {         return null;     }     string contactname = null;     if(cursor.movetofirst()) {         contactname = cursor.getstring(cursor.getcolumnindex(contactscontract.phonelookup.display_name));     }      if(cursor != null && !cursor.isclosed()) {         cursor.close();     }      if (contactname != null) {         return contactname;     } else {         return phonenumber;     }  } 

edit: contact name with

string name = contact_map.get(cursor.getstring(sender_address)); 

hope helps!


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -