From 6998182a2a3a79445eb3602e81a2a362449f32fc Mon Sep 17 00:00:00 2001 From: ksegla Date: Sun, 11 Mar 2018 01:21:28 -0500 Subject: [PATCH] Decode utf-8 before presentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is needed when the strings are encoded in utf8. The encoding is needed for special characters (as simple as é) and smileys. In my use case, I only need title, body and big_text (not familiar with the new additions: action, etc.) but any string in the notification could need decoding. String X = bundle.getString("X") X= URLDecoder.decode( X, "UTF-8" ); Medium term, it could be nice to have a tag for encoding in the initial message that would trigger or not a decoding. --- .../evollu/react/fcm/SendNotificationTask.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java b/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java index b9db6cb..d089aff 100644 --- a/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java +++ b/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLDecoder; import static com.facebook.react.common.ReactConstants.TAG; @@ -53,11 +54,13 @@ public class SendNotificationTask extends AsyncTask { String intentClassName = getMainActivityClassName(); if (intentClassName == null) { return null; - } + } - if (bundle.getString("body") == null) { + String body = bundle.getString("body"); + if (body == null) { return null; } + body = URLDecoder.decode( body, "UTF-8" ); Resources res = mContext.getResources(); String packageName = mContext.getPackageName(); @@ -67,10 +70,11 @@ public class SendNotificationTask extends AsyncTask { ApplicationInfo appInfo = mContext.getApplicationInfo(); title = mContext.getPackageManager().getApplicationLabel(appInfo).toString(); } + title = URLDecoder.decode( title, "UTF-8" ); NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext) .setContentTitle(title) - .setContentText(bundle.getString("body")) + .setContentText(body) .setTicker(bundle.getString("ticker")) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setAutoCancel(bundle.getBoolean("auto_cancel", true)) @@ -131,7 +135,8 @@ public class SendNotificationTask extends AsyncTask { //big text String bigText = bundle.getString("big_text"); - if(bigText != null){ + if(bigText != null){ + bigText = URLDecoder.decode( bigText, "UTF-8" ); notification.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText)); } @@ -152,7 +157,7 @@ public class SendNotificationTask extends AsyncTask { } } bigPicture.setBigContentTitle(title); - bigPicture.setSummaryText(bundle.getString("body")); + bigPicture.setSummaryText(body); notification.setStyle(bigPicture); } -- 2.26.2