How to get contact name for sms conversations?

前端 未结 2 398
时光说笑
时光说笑 2021-01-14 03:18

I\'m retrieving list of last sms/mms conversations using following query:

String[] columns={\"type\", \"address\", \"date\", \"body\", \"conversation_id\"};
         


        
2条回答
  •  半阙折子戏
    2021-01-14 03:53

    Try this:

    Log.i(TAG,"load_contact for "+Phone_numb);
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(Phone_numb));
    String name = "?";
    
    ContentResolver contentResolver = getContentResolver();
    Cursor contactLookup = contentResolver.query(uri, 
        new String[] { BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);
    
    try {
        if (contactLookup != null && contactLookup.getCount() > 0) {
            contactLookup.moveToNext();
            name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
        } else {
             return Phone_numb;
        }
    } finally {
        if (contactLookup != null) {
            contactLookup.close();
        }
    }
    

提交回复
热议问题