0
私はhttpでGcmマルチキャストメッセージングを使用しています、私は任意の数のIDを提供し、メッセージを送信します... 私の最初のマルチキャストは35 ID ... 第二と第三及びマルチキャストに行くだけで7 IDを含めるが、私はまだ(代わりに7の)35件のメッセージの応答を受け取る私は7つのメッセージをGCMを投げて送信し、35のメッセージのための応答を受け取ります
HTTP経由で送信のためのコード:
try{
HttpURLConnection connection = (HttpURLConnection) new URL("https://android.googleapis.com/gcm/send").openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "application/json");
connection.setRequestProperty("Authorization", "key=AIzaSyASH05wdoY42OkmCvGwEbkihKzcwRCfDnQ");
// Write to the connection
OutputStream output = connection.getOutputStream();
output.write(content.getBytes(charset));// content is a Json message with 7 IDs in the field (registration_ids:"xxxxx","xxxx",....)
output.close();
InputStream inputStream = connection.getErrorStream();
if (inputStream == null)
inputStream = connection.getInputStream();
// Read everything from our stream
BufferedReader responseReader = new BufferedReader(new InputStreamReader(inputStream, charset));
String inputLine;
while ((inputLine = responseReader.readLine()) != null) {
response.append(inputLine);
}
responseReader.close();
}catch(IOException io)
{
System.err.println("Error3 "+io);
}
return response.toString();
}
try{
HttpURLConnection connection = (HttpURLConnection) new URL(http_url_old).openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "application/json");
connection.setRequestProperty("Authorization", "key=AIzaSyASH05wdoY42OkmCvGwEbkihKzcwRCfDnQ");
// Write to the connection
OutputStream output = connection.getOutputStream();
output.write(content.getBytes(charset));
output.close();
// Check the error stream first, if this is null then there have been no issues with the request
InputStream inputStream = connection.getErrorStream();
if (inputStream == null)
inputStream = connection.getInputStream();
// Read everything from our stream
BufferedReader responseReader = new BufferedReader(new InputStreamReader(inputStream, charset));
String inputLine;
while ((inputLine = responseReader.readLine()) != null) {
response.append(inputLine);
}
responseReader.close();
}catch(IOException io)
{
System.err.println("Error3 "+io);
}
return response.toString();
}
私は応答を受信すると、サーバは次のように応答します。
{ "multicast_id":6414471465709567733、 "成功":28、 "失敗":7、 "canonical_ids":0、 "結果":[{ "メッセージ_.... ect
28 + 7 = 35、私はちょうど7メッセージを送信します! 私が何回も送った後に(35のために)応答するちょうど7つのIDを含んでいるちょうどマルチキャスト!
どのように正しい応答を得るには? 「レスポンス」の文字列が
ソリューション成長を維持して
response.append(inputLine);
私は新しい結果を追加します..
文字列に私は新しいマルチキャストを送信するたびにリセット