【发布时间】:2016-08-22 14:52:32
【问题描述】:
当我在设备中收到通知时,我无法避免看到奇怪的字符,例如:é。
GcmListenerService.class
public void onMessageReceived(String from, Bundle data) {
String tit = data.getString("title");
String message = data.getString("body");
String title = null;
try {
title= URLDecoder.decode(tit, "UTF-8"); // tit and title have the same output
sendNotification(title,message)
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
在服务器端我进行编码:
$payload = array('body' => utf8_encode($texto),
'title' => utf8_encode($name),
'Room' => utf8_encode($texto));
$data = array(
'data' => $payload,
'to' => $tokenDevice);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json; charset=utf-8');
我做错了什么?谢谢
【问题讨论】:
-
编码后服务器端的字符串如何?
标签: android encoding utf-8 push-notification