Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

[ANDROID] support html tags for message and bigText fields #1469

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
import android.os.Build;
import android.os.Bundle;
import android.service.notification.StatusBarNotification;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.util.Log;

import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.core.text.HtmlCompat;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
Expand All @@ -44,6 +48,7 @@
import java.util.List;
import java.util.Map;

import static android.text.Html.FROM_HTML_MODE_LEGACY;
import static com.dieam.reactnativepushnotification.modules.RNPushNotification.LOG_TAG;
import static com.dieam.reactnativepushnotification.modules.RNPushNotificationAttributes.fromJson;

Expand Down Expand Up @@ -328,7 +333,11 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
// Changing Default mode of notification
notification.setDefaults(Notification.DEFAULT_LIGHTS);
}


Spanned styledText = HtmlCompat.fromHtml(bundle.getString("message"), HtmlCompat.FROM_HTML_MODE_LEGACY);

notification.setContentText(styledText);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { // API 20 and higher
String group = bundle.getString("group");

Expand Down Expand Up @@ -390,7 +399,25 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
notification.setLargeIcon(largeIconBitmap);
}

String message = bundle.getString("message");
notification.setSmallIcon(smallIconResId);

Spanned bigText = null;
String bigTextString = bundle.getString("bigText");

if(bigTextString == null) {
bigText = styledText;
} else {
bigText = HtmlCompat.fromHtml(bigTextString, HtmlCompat.FROM_HTML_MODE_LEGACY);
}

Spanned message = null;
String messageString = bundle.getString("message");

if(messageString == null) {
message = styledText;
} else {
message = HtmlCompat.fromHtml(messageString, HtmlCompat.FROM_HTML_MODE_LEGACY);
}

notification.setContentText(message);

Expand All @@ -399,8 +426,6 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
if (subText != null) {
notification.setSubText(subText);
}

String bigText = bundle.getString("bigText");

if (bigText == null) {
bigText = message;
Expand Down