为什么我的gcm只授权我的设备注册ID为同一个应用程序?

时间:2014-02-03 05:01:46

标签: java android google-cloud-messaging

我试图通过制作json数组并作为http发送来通过java代码发送gcm推送消息..

我有不同设备相同应用的注册ID数组。 问题: 问题是每当我将gcm消息发送到注册ID数组时,我只获得与我发送消息的相同注册ID(设备)的成功消息,而另一个则显示我的返回消息中的无效注册ID错误GCM。

App仅验证我自己的注册ID!为什么? 请尝试向我提供一些信息。那个api键??

1 个答案:

答案 0 :(得分:0)

private void sendPush(ArrayList registrationids,String message)抛出异常{

HttpPost httppost = new HttpPost(“https://android.googleapis.com/gcm/send”);

httppost.addHeader("Authorization", "key="key");
httppost.addHeader("Content-Type", "application/json");

JSONObject topObject=new JSONObject();


JSONObject dataObject=new JSONObject();
dataObject.put("msg", message);
dataObject.put("title", "Test Title");

topObject.put("data", dataObject);

JSONArray arObject=new JSONArray();



for(int i=0;i<registrationids.size();i++)
{
arObject.put(registrationids.get(i));
Log.e("", registrationids.get(i)+"");
}

//arObject.put(registrationids.get(1));


topObject.put("registration_ids", arObject);

String jsonBody=topObject.toString();
httppost.setEntity(new StringEntity(jsonBody,"UTF-8"));





HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse = httpclient.execute(httppost);
HttpEntity resEntity = httpResponse.getEntity();

// Get the HTTP Status Code
int statusCode = httpResponse.getStatusLine().getStatusCode();

// Get the contents of the response
InputStream input = resEntity.getContent();
String responseBody = Utils.convertStreamToString(input);
input.close();

// Print the response code and message body
Log.e("HTTP Status Code:", statusCode+"");
Log.e("responseBody", responseBody);

}