1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-03-19 18:35:34 +00:00

Show contact photo in new message notification

This commit is contained in:
M66B 2018-11-06 15:40:00 +00:00
parent a2f3fe57c7
commit eb6203ab85

View file

@ -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);