I'm trying to send a push notification(emoji or UTF-8 text ) using Firebase. Between iOS and iOS, between Android and Android and from iOS to Android, it works well. But only from Android to iOS, it doesn't work and the texts are broken.
I used URLEncoder.encode function for UTF-8 encoding. Here is the code for sending.
JSONObject jsonObject = new JSONObject();
jsonObject.put("to", mCurrentUser.token);
JSONObject notificationObject = new JSONObject();
notificationObject.put("title", title);
notificationObject.put("body", URLEncoder.encode(mMessage.text, "UTF-8"));
notificationObject.put("content_available", true);
jsonObject.put("notification", notificationObject);
DataOutputStream wr = new DataOutputStream(httpURLConnection.getOutputStream());
wr.writeBytes(jsonObject.toString());
wr.flush();
Please help me. Thanks in advance.
I finally found the solution out. Android - How to Convert String to utf-8 in android
Thanks to @Paras.
public class StringFormatter {
// convert UTF-8 to internal Java String format
public static String convertUTF8ToString(String s) {
String out = null;
try {
out = new String(s.getBytes("ISO-8859-1"), "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
return null;
}
return out;
}
// convert internal Java String format to UTF-8
public static String convertStringToUTF8(String s) {
String out = null;
try {
out = new String(s.getBytes("UTF-8"), "ISO-8859-1");
} catch (java.io.UnsupportedEncodingException e) {
return null;
}
return out;
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments