mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 05:07:40 +00:00
refactor getTickerText
This commit is contained in:
parent
132e4e7e0f
commit
dbd9ece110
@ -489,32 +489,28 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
||||
* instead the ticker text.
|
||||
*/
|
||||
private String getTickerText(Notification notification) {
|
||||
final String TITLE_KEY = "android.title";
|
||||
final String TEXT_KEY = "android.text";
|
||||
String ticker = "";
|
||||
|
||||
if (notification != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
try {
|
||||
Bundle extras = notification.extras;
|
||||
String extraTitle = extractStringFromExtra(extras, TITLE_KEY);
|
||||
String extraText = extractStringFromExtra(extras, TEXT_KEY);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
try {
|
||||
Bundle extras = notification.extras;
|
||||
String extraTitle = extractStringFromExtra(extras, Notification.EXTRA_TITLE);
|
||||
String extraText = extractStringFromExtra(extras, Notification.EXTRA_TEXT);
|
||||
|
||||
if (extraTitle != null && extraText != null && !extraText.isEmpty()) {
|
||||
ticker = extraTitle + ": " + extraText;
|
||||
} else if (extraTitle != null) {
|
||||
ticker = extraTitle;
|
||||
} else if (extraText != null) {
|
||||
ticker = extraText;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "problem parsing notification extras for " + notification.tickerText, e);
|
||||
if (extraTitle != null && extraText != null && !extraText.isEmpty()) {
|
||||
ticker = extraTitle + ": " + extraText;
|
||||
} else if (extraTitle != null) {
|
||||
ticker = extraTitle;
|
||||
} else if (extraText != null) {
|
||||
ticker = extraText;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "problem parsing notification extras for " + notification.tickerText, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (ticker.isEmpty()) {
|
||||
ticker = (notification.tickerText != null) ? notification.tickerText.toString() : "";
|
||||
}
|
||||
if (ticker.isEmpty()) {
|
||||
ticker = (notification.tickerText != null) ? notification.tickerText.toString() : "";
|
||||
}
|
||||
|
||||
return ticker;
|
||||
|
Loading…
x
Reference in New Issue
Block a user