I am tring to get contacts with photos, but photo blob is always empty
Cursor c = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[] {
ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.Photo.PHOTO,
ContactsContract.CommonDataKinds.Phone.NUMBER
}, ContactsContract.RawContacts.ACCOUNT_TYPE + " <> 'google' ", null, null);
ArrayList<ContentValues> valuesList = new ArrayList<>();
String[] split;
String nameShort;
while (c.moveToNext()) {
ContentValues cv = new ContentValues();
String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String photo = c.getString(c.getColumnIndex(ContactsContract.Contacts.Photo.PHOTO));
String number =
c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if (name.length() > 0) {
split = name.split(" ");
nameShort = "";
nameShort += split[0].charAt(0);
if (split.length > 1) nameShort += split[1].charAt(0);
} else {
nameShort = "";
}
number = number.replaceAll("[^0-9+#*]", "");
cv.put(ContactsTable.NAME, name);
cv.put(ContactsTable.NUMBER, number);
cv.put(ContactsTable.PHOTO, photo);
cv.put(ContactsTable.NAME_SHORT, nameShort);
valuesList.add(cv);
}
c.close();
How to get photopreview?
Aucun commentaire:
Enregistrer un commentaire