From eb6203ab85065b344355ef972f9f1eeb2667b325 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 6 Nov 2018 15:40:00 +0000 Subject: [PATCH] Show contact photo in new message notification --- .../eu/faircode/email/ServiceSynchronize.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 6446e15ffc..c1a4fd23e3 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -512,13 +512,31 @@ public class ServiceSynchronize extends LifecycleService { if (!TextUtils.isEmpty(message.subject)) mbuilder.setContentText(message.subject); - if (!TextUtils.isEmpty(message.avatar)) + if (!TextUtils.isEmpty(message.avatar)) { + Cursor cursor = null; + try { + cursor = getContentResolver().query( + Uri.parse(message.avatar), + new String[]{ContactsContract.Contacts._ID}, + null, null, null); + if (cursor.moveToNext()) { + Uri photo = Uri.withAppendedPath( + ContactsContract.Contacts.CONTENT_URI, + cursor.getLong(0) + "/photo"); + mbuilder.setLargeIcon(Icon.createWithContentUri(photo)); + } + } finally { + if (cursor != null) + cursor.close(); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) mbuilder.addPerson(new Person.Builder() .setUri(message.avatar) .build()); else mbuilder.addPerson(message.avatar); + } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) mbuilder.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN);