raghav / gcm

Automatically exported from code.google.com/p/gcm
Apache License 2.0
0 stars 0 forks source link

MulticastResult Send Message Arabic Text Displaying ???????? #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Sender sender = new Sender(AuthorisedToken); 
Message message = new Message.Builder() 
.collapseKey("1") 
.timeToLive(3) 
.delayWhileIdle(true) 
.addData("message", 
"this text will be seen in notification bar!") 
.build(); 

MulticastResult result = sender.sendNoRetry(message, devicesList); 

if i used Result  result =sender.send method Arabic is correct
Whene i see the Code of Sender Class there UTF8 Convert all Request Body
But in Case of MulticastResult  There is No UTF8 in Payload 
My Message Builder Like above how to encode in UTF8 while i am using 
MulticastResult  Method 

Original issue reported on code.google.com by abhimany...@gmail.com on 15 Jul 2013 at 2:49

GoogleCodeExporter commented 9 years ago
yes i got the salution for this

Original comment by abhimany...@gmail.com on 25 Jul 2013 at 1:57

GoogleCodeExporter commented 9 years ago
Please, can you explain how did you resolve this issue?

Original comment by fernando...@gmail.com on 3 Jan 2014 at 6:50

GoogleCodeExporter commented 9 years ago
MulticastResult result = sender.sendNoRetry(message, devicesList); 

will not help you .you need send json parameter to gsm url.use http Post method 
like 

   HttpClient httpClient = new DefaultHttpClient();
                    try{
                    String messsage="";
                    JSONObject js=new JSONObject();
                    JSONObject js1=new JSONObject();
                    js.put("delay_while_idle", false) ;
                    js.put("collapse_key","0") ;
                    js1.put("payload",msg1) ;
                    js.put("time_to_live",600) ;
                    js.put("data", js1) ;
                    js.put("registration_ids", arraylist) ;
                    String message=js.toJSONString();

HttpPost request = new HttpPost("https://android.googleapis.com/gcm/send");
StringEntity params =new StringEntity(message,"UTF-8");
request.addHeader("Authorization", "key=Your App RegistrationId");
                    request.addHeader("content-type", "application/json;charset=UTF-8");
                    request.setEntity(params);
                    HttpResponse response = httpClient.execute(request);
                     BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                        String line = "";
                        while ((line = rd.readLine()) != null) {
                           //Parse our JSON response 
                            System.out.println(line);
                           JSONParser j = new JSONParser();
                           JSONObject o = (JSONObject)j.parse(line);
                           //Map r = (Map)o.get("success");
                           //log.info("check sucsess value>>>>>>");
                           succ=(o.get("success")).toString();

                                                }

        } catch (Exception e) { 
                       e.getMessage();
                    } 

Then only u can send arabic text.

result whould be Json Formate:=

{"multicast_id":8676960544645135217,"success":736,"failure":264,"canonical_ids":
0,"results{"message_id":"0:1386053246577771%25796c8300000030"},{"message_id":"0:
1386053246575977%25796c8300000030"},{"error":"NotRegistered"}]}

Abhimanyu

Original comment by abhimany...@gmail.com on 8 Jan 2014 at 1:35

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
thanx for nice help but just change   byte[] bytes = body.getBytes("UTF-8"); in 
post method . 

Original comment by nirajtha...@gmail.com on 3 Apr 2014 at 2:32

GoogleCodeExporter commented 9 years ago
You can find the fix for this bug in issue #17

Original comment by KurtHu...@gmail.com on 25 Aug 2014 at 9:15

GoogleCodeExporter commented 9 years ago
You can find a repo with the fix of issue #17 here:

https://github.com/kurthuwig/gcm/commit/d37f4d1c37ed8deaf1a161ca7b881c1d843f80df

Original comment by KurtHu...@gmail.com on 25 Aug 2014 at 9:39