Commit 6998182a authored by ksegla's avatar ksegla Committed by GitHub

Decode utf-8 before presentation

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.
parent ea1413e7
......@@ -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;
......@@ -55,9 +56,11 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
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<Void, Void, Void> {
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))
......@@ -132,6 +136,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
//big text
String bigText = bundle.getString("big_text");
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<Void, Void, Void> {
}
}
bigPicture.setBigContentTitle(title);
bigPicture.setSummaryText(bundle.getString("body"));
bigPicture.setSummaryText(body);
notification.setStyle(bigPicture);
}
......
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