问题描述
我有一个Java Spring Boot Web服务,我正在尝试将推送通知发送到iOS设备。
我面临的问题是直接粘贴的表情文字,例如
String emoji = "?";
或其代码,例如
String emoji = "\uD83D\uDE0A";
它显示为?
(问号)
我尝试将其作为UTF_8个字符的字节来获取,
byte[] emojis = user.getEmoji().getBytes(); //Here user.getEmoji() returns a collection of 2-3 emojis
String emojisAsstring = new String(emojis,StandardCharsets.UTF_8);
Integer EmojicodePoint = emojisAsstring.codePointAt(emojisAsstring.offsetByCodePoints(0,0));
char emojiChars[] = {Character.highSurrogate(EmojicodePoint),Character.lowSurrogate(EmojicodePoint)};
但是它仍然显示为问号。
我还尝试过使用"\xE2\x9A\xA1"
之类的UTF-8代码,但此代码只是按照通知中的内容打印出来。
此外,当我使用FCM API从邮递员调用通知API并粘贴表情符号时,它会在通知中显示表情符号,通过Java Web服务完成时只会显示为问号。
@RequestMapping(value = "/send",method = RequestMethod.GET,produces = "application/json")
public static ResponseEntity<String> send(String message,String devicetoken,Integer type,Object response,String userNameAsTitle) {
//response.setMessage(message);
//response.setNotificationType(type);
JSONObject body = new JSONObject();
body.put("to",devicetoken);
body.put("priority","high");
Map<String,Object> map = new HashMap<>();
map.put("title",userNameAsTitle);
map.put("body",message);
//map.put("alert",descprtion);
map.put("type",type);
map.put("badge",1);
map.put("sound","default");
map.put("response",response);
JSONObject notification = new JSONObject(map);
//body.put("notification",notification);
body.put("notification",notification);
httpentity<String> request = new httpentity<>(body.toString());
CompletableFuture<String> pushNotification = androidPushNotificationsService.send(request);
CompletableFuture.allOf(pushNotification).join();
try {
String firebaseResponse = pushNotification.get();
System.out.println(firebaseResponse.toString());
return new ResponseEntity<>(firebaseResponse.toString(),HttpStatus.OK);
} catch (InterruptedException | ExecutionException e) {
e.printstacktrace();
}
return new ResponseEntity<>("Push Notification ERROR!",HttpStatus.BAD_REQUEST);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)