根据
的文件http://developer.android.com/google/gcm/client.html
http://developer.android.com/google/gcm/server.html
您必须实施的第三方应用程序服务器。此应用程序服务器通过选定的GCM连接服务器将数据发送到启用GCM的Android应用程序。
从上面来看,它意味着您无法直接从客户端向另一个客户端发送消息。
有人请确认。
答案 0 :(得分:0)
可以直接从您的设备向没有任何第三方服务器的Google服务器发送GCM消息。 只需像这个例子一样运行AsyncTask:
HttpPost httppost;
try
{
httppost = new HttpPost("https://android.googleapis.com/gcm/send");
}
catch (IllegalArgumentException e)
{
return false;
}
httppost.setHeader("Authorization","key=xxxxxxxxxxxxxx");
httppost.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
postParams.add(new BasicNameValuePair("registration_id", "xxxxxxxxxxxxx"));
postParams.add(new BasicNameValuePair("data.mode", "exampleContentOfYourMessage"));
HttpResponse response;
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity entity;
try {
httppost.setEntity(new UrlEncodedFormEntity(postParams, "utf-8"));
}
catch (UnsupportedEncodingException e)
{
return false;
}
try {
response = httpClient.execute(httppost);
} catch (ClientProtocolException e) {
return false;
} catch (IOException e) {
return false;
}
entity = response.getEntity();
if (entity != null && response.getStatusLine().getStatusCode() == 200)
{
return true;
}
else
{
Log.e("Tag","No Connection");
return false;
}
但我不知道如何向多个注册ID发送GCM消息:(
问候,Malte