Android Get Contact Picture from Call Log

后端 未结 5 1237
南笙
南笙 2020-12-18 13:07

It was pretty easy to get the Contact picture when querying the People.CONTENT_URI, with a simple

People.loadContactPhoto(activity, ContentUr         


        
5条回答
  •  情话喂你
    2020-12-18 13:40

    All above answer is correct.You can also get photo by this...

    c.getString(c.getColumnIndex(CallLog.Calls.CACHED_PHOTO_URI));

    work in SDK >=23

    if you are working with minimum SDK...

    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(num));
            uri = ((phone_uri != null) ? Uri.parse(phone_uri) : uri);
            Cursor cursor = getContext().getContentResolver().query(uri, null, null, null, null);
    
            if (cursor != null) {
                if (cursor.moveToNext()) {
                    String id = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup._ID));
                    String name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
                    image_uri = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.PHOTO_URI));
                    Log.d(TAG, "name " + name + " id "+id+" image_uri "+ image_uri);
                }
                cursor.close();
            }
    

提交回复
热议问题