From 8b145b4c6a6a8af38f6ba813b4145e32e2f8e416 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Sun, 19 May 2019 20:05:58 +0200 Subject: [PATCH] Simplify notification title/text extraction --- .../NotificationsPlugin.java | 46 ++----------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java index 90e7db6f..ccf6b883 100644 --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java @@ -293,8 +293,11 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. pendingIntents.put(rn.id, rn); } np.set("ticker", getTickerText(notification)); - np.set("title", getNotificationTitle(notification)); - np.set("text", getNotificationText(notification)); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + np.set("title", notification.extras.getString(Notification.EXTRA_TITLE)); + np.set("text", notification.extras.getString(Notification.EXTRA_TEXT)); + } } device.sendPacket(np); @@ -358,25 +361,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. pendingIntents.remove(id); } - private String getNotificationTitle(Notification notification) { - final String TITLE_KEY = "android.title"; - final String TEXT_KEY = "android.text"; - String title = ""; - - if (notification != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - try { - Bundle extras = notification.extras; - title = extractStringFromExtra(extras, TITLE_KEY); - } catch (Exception e) { - Log.e("NotificationPlugin", "problem parsing notification extras for " + notification.tickerText, e); - } - } - } - - return title; - } - private RepliableNotification extractRepliableNotification(StatusBarNotification statusBarNotification) { RepliableNotification repliableNotification = new RepliableNotification(); @@ -404,26 +388,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. return repliableNotification; } - private String getNotificationText(Notification notification) { - final String TEXT_KEY = "android.text"; - String text = ""; - - if (notification != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - try { - Bundle extras = notification.extras; - Object extraTextExtra = extras.get(TEXT_KEY); - if (extraTextExtra != null) text = extraTextExtra.toString(); - } catch (Exception e) { - Log.e("NotificationPlugin", "problem parsing notification extras for " + notification.tickerText, e); - } - } - } - - return text; - } - - private static String extractStringFromExtra(Bundle extras, String key) { Object extra = extras.get(key); if (extra == null) {