Extract EXTRA_BIG_TEXT instead of EXTRA_TEXT if available.

This makes K9 Mail usable with only using generic notifcations on Android >=5
(It shows the message preview now)
master
Andreas Shimokawa 2016-10-18 23:44:00 +02:00
parent 9dc9ad6ce4
commit 336ffd5bf7
1 changed files with 23 additions and 5 deletions

View File

@ -313,16 +313,24 @@ public class NotificationListener extends NotificationListenerService {
private void dissectNotificationTo(Notification notification, NotificationSpec notificationSpec) {
Bundle extras = notification.extras;
//dumpExtras(extras);
CharSequence title = extras.getCharSequence(Notification.EXTRA_TITLE);
if (title != null) {
notificationSpec.title = title.toString();
}
if (extras.containsKey(Notification.EXTRA_TEXT)) {
CharSequence contentCS = extras.getCharSequence(Notification.EXTRA_TEXT);
if (contentCS != null) {
notificationSpec.body = contentCS.toString();
}
CharSequence contentCS = null;
if (extras.containsKey(Notification.EXTRA_BIG_TEXT)) {
contentCS = extras.getCharSequence(Notification.EXTRA_BIG_TEXT);
} else if (extras.containsKey(Notification.EXTRA_TEXT)) {
contentCS = extras.getCharSequence(Notification.EXTRA_TEXT);
}
if (contentCS != null) {
notificationSpec.body = contentCS.toString();
}
}
private boolean isServiceRunning() {
@ -412,4 +420,14 @@ public class NotificationListener extends NotificationListenerService {
public void onNotificationRemoved(StatusBarNotification sbn) {
}
private void dumpExtras(Bundle bundle) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
if (value == null) {
continue;
}
LOG.debug(String.format("Notification extra: %s %s (%s)", key, value.toString(), value.getClass().getName()));
}
}
}