Show contact photo in new message notification

pull/146/head
M66B 7 years ago
parent a2f3fe57c7
commit eb6203ab85

@ -512,13 +512,31 @@ public class ServiceSynchronize extends LifecycleService {
if (!TextUtils.isEmpty(message.subject)) if (!TextUtils.isEmpty(message.subject))
mbuilder.setContentText(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) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
mbuilder.addPerson(new Person.Builder() mbuilder.addPerson(new Person.Builder()
.setUri(message.avatar) .setUri(message.avatar)
.build()); .build());
else else
mbuilder.addPerson(message.avatar); mbuilder.addPerson(message.avatar);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
mbuilder.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN); mbuilder.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN);

Loading…
Cancel
Save