Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

UTF8 support on android: the notification text (on android only) is shown with "???" #461

Closed
yoav-zibin opened this issue Dec 27, 2015 · 2 comments

Comments

@yoav-zibin
Copy link

Hi,
Have you ever tested non-english notifications on android? I tried both Hebrew and Chinese, and it doesn't work.

I'm sending the same notification text to GCM and APNS, and it is shown correctly on iphone, but not android.
See the attached printscreens:
On android it is shown with "?????" :
screenshot_20151227-133049
On iOS it is shown correct:
daadbe70-f649-459f-951a-afde65b6ac5e

I captured a bug report and this is what I see:
12-27 12:38:55.650 21639 21679 D PushPlugin_GCMIntentService: replace key collapse_key with collapse_key
12-27 12:38:55.650 21639 21679 D PushPlugin_GCMIntentService: background
12-27 12:38:55.650 21639 21679 D PushPlugin_GCMIntentService: message =[yoav local chrome ????? ???? ?????]
12-27 12:38:55.650 21639 21679 D PushPlugin_GCMIntentService: title =[???? ???]
12-27 12:38:55.650 21639 21679 D PushPlugin_GCMIntentService: contentAvailable =[null]

When I sent to GCM, I use AppEngine, and I logged the exact post message:

2015-12-27 12:38:58.172
com.multiplayer.PostMessage sendPost: Sending POST message to url: https://gcm-http.googleapis.com/gcm/send
Message: {"registration_ids":["fQ3Dg8_jcmM:APA91bEFChZPmKPOD9wjWzj8kxGQ75AVyfYZ0rs4EIt51fByS4yH65XcI5hCrSqjflcLzlXO7y_FAWXX3MdbNvM3acLLG3LZ6YcstTGA2VyWMnXGm6bWtmrKp3JvACYnGUfhy6H2hAUM"],"data":{"title":"משחק חדש","message":"yoav local chrome הזמין אותך למשחק","matchId":"6635885969081947891","notificationOpponentId":"5720693702393856","updatedTimestampMillis":"1451237937965","notId":"575528018","matchInfoJson":"{"gameVariant":0,"matchId":"6635885969081947891","createdTimestampMillis":"1451237937965","updatedTimestampMillis":"1451237937965","isReservedAutoMatch":false,"notificationOpponentId":"0","state":"N4IgLgrgTgdgkjAJgUwB4CFkDMD2VkCyOAbsiAFwAMANONPEmhQIy3JIECGYAxgBYBlHnmQBnCjAgAbKbQC2JZADkIcgEbIoLWlE5IccgcmSIKISgDoArABYA7ADYAHAE4bLgMyV7lOx6sgtFKcomBEpBQA2qCiyGAAKvQUoJCwCCioLAC+WdQxcckgANbIAJ5modxktMScUhBk5KAoUmCchVA4AO4UNCDCUr25IGo4nFCm5JGRIAAagSALIAC61DNLtCtri5uby8s5WasgwaECbWCNwMM80PgwYOdVhZWXhS1tHd29tANDtKNxpNpnMNotVutduDtmCVgdhqcwAA1ACWohRaikyHiOGSNzu7GRaIxWJxeKyQA\u003d\u003d","lastPlayerIndex":0,"nextPlayerIndex":1,"playersInfo":[{"playerId":"5720693702393856","displayName":"yoav local chrome","avatarImageUrl":"http://www.multiplayer-gaming.com/v1/dist/imgs/avatar38.gif"},{"playerId":"4791088564928512","displayName":"Yoav Zibin","avatarImageUrl":"http://graph.facebook.com/10152824135331125/picture?square\u003dsquare"}]}"},"notification":{"title":"משחק חדש","body":"yoav local chrome הזמין אותך למשחק"}}
I 2015-12-27 12:38:58.353

com.multiplayer.PostMessage sendPost: POST returned: {"multicast_id":5627025799402887992,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1451237938334570%224af683224af683"}]}

I'm pretty sure the problem is here:

I believe this:
Object json = extras.get(key);
should be:
String json = URLDecoder.decode(extras.get(key).toString(), "UTF-8");
See also:
http://stackoverflow.com/questions/14677821/received-gcm-message-shows-with-garbled-text

(I'm using phonegap build, so I can't really test if this solution works :))

@yoav-zibin
Copy link
Author

Never mind! I found the solution to do it on the server side:
http://stackoverflow.com/questions/22861828/java-string-getbytesutf-8-javascript-equivalent

I had to use both:
Content-Type: application/json;charset=UTF-8

AND:
byte[] bytes = message.getBytes("UTF-8");
OutputStream out = connection.getOutputStream();
try {
out.write(bytes);
} finally {
out.close();
}

(before I was writing the string directly, and not the bytes).

Hope it will help someone else :)

@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant