Android GCM unicode charcters are not received

前端 未结 3 1209
情深已故
情深已故 2020-12-19 03:24

This is my server side code or android side code. This code is working fine only for English messages. If I use Unicode charters like use Arabic language then it shows nothi

相关标签:
3条回答
  • 2020-12-19 03:32

    André Oriani has the general idea for the fix. Even though the message is placed in the body of the request, it still needs to url encoded.

    string postData = string.Format("registration_id={0}&data.payload={1}&collapse_key={2}", id, msg, collaspeKey);
    

    should be replaced with

    string postData = string.Format("registration_id={0}&data.payload={1}&collapse_key={2}", id, HttpUtility.UrlEncode(msg), HttpUtility.UrlEncode(collaspeKey));
    

    You will need to add a reference to System.Web in order to use HttpUtility. See URL Encoding using C# for more information.

    0 讨论(0)
  • 2020-12-19 03:35

    Have you considered using base64 to encode the string sent through GCM? This way you would remove all encoding problems.

    0 讨论(0)
  • 2020-12-19 03:36

    Here's what solved it for me in Java:

    On the server side:

    encodedMessage = URLEncoder.encode(message, "UTF-8");
    

    In the app:

    decodedMessage = URLDecoder.decode(message, "UTF-8");
    
    0 讨论(0)
提交回复
热议问题