Commit dbd9ece1 authored by Nicolas Fella's avatar Nicolas Fella

refactor getTickerText

parent 132e4e7e
...@@ -489,32 +489,28 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. ...@@ -489,32 +489,28 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
* instead the ticker text. * instead the ticker text.
*/ */
private String getTickerText(Notification notification) { private String getTickerText(Notification notification) {
final String TITLE_KEY = "android.title";
final String TEXT_KEY = "android.text";
String ticker = ""; String ticker = "";
if (notification != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try {
try { Bundle extras = notification.extras;
Bundle extras = notification.extras; String extraTitle = extractStringFromExtra(extras, Notification.EXTRA_TITLE);
String extraTitle = extractStringFromExtra(extras, TITLE_KEY); String extraText = extractStringFromExtra(extras, Notification.EXTRA_TEXT);
String extraText = extractStringFromExtra(extras, TEXT_KEY);
if (extraTitle != null && extraText != null && !extraText.isEmpty()) {
if (extraTitle != null && extraText != null && !extraText.isEmpty()) { ticker = extraTitle + ": " + extraText;
ticker = extraTitle + ": " + extraText; } else if (extraTitle != null) {
} else if (extraTitle != null) { ticker = extraTitle;
ticker = extraTitle; } else if (extraText != null) {
} else if (extraText != null) { ticker = extraText;
ticker = extraText;
}
} catch (Exception e) {
Log.e(TAG, "problem parsing notification extras for " + notification.tickerText, e);
} }
} catch (Exception e) {
Log.e(TAG, "problem parsing notification extras for " + notification.tickerText, e);
} }
}
if (ticker.isEmpty()) { if (ticker.isEmpty()) {
ticker = (notification.tickerText != null) ? notification.tickerText.toString() : ""; ticker = (notification.tickerText != null) ? notification.tickerText.toString() : "";
}
} }
return ticker; return ticker;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment