从java发送GCM推送通知时,我收到了以下回复。
{ “multicast_id”:8802417572032089725, “成功”:0, “失败”:5 “canonical_ids”:0 “结果”:[{ “错误”: “NotRegistered”},{ “错误”:“NotRegistered “},{” 错误 “:” NotRegistered “},{” 错误 “:” InvalidRegistration “},{” 错误 “:” MismatchSenderId“}]}
。
这是我的代码:
PostMethod post = null;
try
{ // Below is a good tutorial , how to post json data
// http://hmkcode.com/android-send-json-data-to-server/
String url = "https://android.googleapis.com/gcm/send";
HttpClient httpclient = getHttpClient();
post = new PostMethod(url);
JSONObject mainData = new JSONObject();
try
{
JSONObject data = new JSONObject();
data.putOpt("message", "my message");
data.putOpt("title", "My title");
JSONArray regIds = new JSONArray();
for (String s : registrationIds)
{
regIds.put(s);
}
mainData.put("registration_ids", regIds);
mainData.put("data", data);
}
catch (JSONException e)
{
LOG.info(e.getCause(), e);
}
post.setRequestBody(mainData.toString());
post.setRequestHeader("Authorization", "key=" + googleApiKey);
post.setRequestHeader("Content-Type", "application/json");
httpclient.executeMethod(post);
String response = new String(post.getResponseBody());
LOG.info("Response body of Mobile No : "+ mobileNo + " is : " +response);
}
catch (MalformedURLException e)
{
LOG.info(e.getCause(), e);
}
catch (IOException e)
{
LOG.info(e.getCause(), e);
}
finally
{
if(post != null)
{
post.releaseConnection();
}
}