mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-02 23:25:10 +00:00
Simplify notification title/text extraction
This commit is contained in:
@@ -293,8 +293,11 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
pendingIntents.put(rn.id, rn);
|
pendingIntents.put(rn.id, rn);
|
||||||
}
|
}
|
||||||
np.set("ticker", getTickerText(notification));
|
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);
|
device.sendPacket(np);
|
||||||
@@ -358,25 +361,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
pendingIntents.remove(id);
|
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) {
|
private RepliableNotification extractRepliableNotification(StatusBarNotification statusBarNotification) {
|
||||||
RepliableNotification repliableNotification = new RepliableNotification();
|
RepliableNotification repliableNotification = new RepliableNotification();
|
||||||
|
|
||||||
@@ -404,26 +388,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
return repliableNotification;
|
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) {
|
private static String extractStringFromExtra(Bundle extras, String key) {
|
||||||
Object extra = extras.get(key);
|
Object extra = extras.get(key);
|
||||||
if (extra == null) {
|
if (extra == null) {
|
||||||
|
Reference in New Issue
Block a user