getContentFromHtml

protected fun getContentFromHtml(content: String): CharSequence

Converts HTML-formatted string to styled CharSequence for display in notifications.

Push notification messages can contain HTML formatting (bold, italic, etc.). This helper method parses HTML tags and returns a styled CharSequence that preserves the formatting when displayed in the notification.

Supported HTML tags:, , , , , and other basic formatting tags supported by fromHtml. Example - Display formatted notification text:


	  
	  public Notification onGenerateNotification(@NonNull PushMessage data) {
	      String channelId = addChannel(data);
	
	      // Convert HTML to styled text
	      CharSequence title = getContentFromHtml(data.getHeader());
	      CharSequence message = getContentFromHtml(data.getMessage());
	
	      NotificationCompat.Builder builder = new NotificationCompat.Builder(
	          getApplicationContext(), channelId)
	          .setContentTitle(title)  // Preserves bold, italic, etc.
	          .setContentText(message)
	          .setSmallIcon(R.drawable.ic_notification);
	
	      return builder.build();
	  }
	

Return

Styled CharSequence with HTML formatting applied, or the original string if empty

Parameters

content

HTML-formatted string from push notification message

See also