how to get contact photo URI

后端 未结 5 1578
夕颜
夕颜 2020-12-01 16:59

I am working with Android Contact ContentProvider. I have a Phone Number and I need to get the URI of the Photo of the contact associated with thi

5条回答
  •  无人及你
    2020-12-01 17:26

    You can get PHOTO_URI by NUMBER just use following code also you can use _ID.

     public static String getContactPhoto(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.PHOTO_URI}, null, null, null);
        if (cursor == null) {
            return null;
        }
        String contactImage= null;
        if (cursor.moveToFirst()) {
            contactImage= cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.PHOTO_URI));
        }
    
        if (!cursor.isClosed()) {
            cursor.close();
        }
        return contactImage;
    }
    

提交回复
热议问题