Use contact display names

Fixes #117
This commit is contained in:
M66B 2018-09-20 11:24:34 +00:00
parent 82b3e0ef58
commit bc6bb15fde
1 changed files with 12 additions and 4 deletions

View File

@ -1660,21 +1660,29 @@ public class ServiceSynchronize extends LifecycleService {
== PackageManager.PERMISSION_GRANTED) { == PackageManager.PERMISSION_GRANTED) {
try { try {
if (message.from != null) if (message.from != null)
for (Address from : message.from) { for (int i = 0; i < message.from.length; i++) {
String email = ((InternetAddress) from).getAddress(); String email = ((InternetAddress) message.from[i]).getAddress();
Cursor cursor = null; Cursor cursor = null;
try { try {
ContentResolver resolver = context.getContentResolver(); ContentResolver resolver = context.getContentResolver();
cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
new String[]{ContactsContract.CommonDataKinds.Photo.CONTACT_ID}, new String[]{
ContactsContract.CommonDataKinds.Photo.CONTACT_ID,
ContactsContract.Contacts.DISPLAY_NAME
},
ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?", ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?",
new String[]{email}, null); new String[]{email}, null);
if (cursor.moveToNext()) { if (cursor.moveToNext()) {
int colContactId = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.CONTACT_ID); int colContactId = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.CONTACT_ID);
int colDisplayName = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
long contactId = cursor.getLong(colContactId); long contactId = cursor.getLong(colContactId);
String displayName = cursor.getString(colDisplayName);
Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId); Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
message.avatar = uri.toString(); message.avatar = uri.toString();
break;
if (!TextUtils.isEmpty(displayName))
((InternetAddress) message.from[i]).setPersonal(displayName);
} }
} finally { } finally {
if (cursor != null) if (cursor != null)