几天前,Android设备的推送通知工作正常,因为到目前为止我的数据库中有大约1000个设备令牌,但今天它没有工作,因为它达到了大约1500个设备令牌。我在服务器端得到java.io.IOException
。
java.io.IOException: Server returned HTTP response code: 400 for URL: https://android.googleapis.com/gcm/send
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1491)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1485)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1139)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
at com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:363)
at com.google.android.gcm.server.Sender.send(Sender.java:261)
at com.orange.server.ws.androidpns.androidPNHandler.run(androidPNHandler.java:58)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://android.googleapis.com/gcm/send
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
at com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:362)
... 2 more
我检查了一个设备令牌它工作正常但是当我的数据库表中有很多设备令牌(> 800)时,我得到了以上异常。这是我的GCM服务器代码。
Sender sender = new Sender("SENDER-ID");
AndroidPNSEntityHandler androidPNSEntityHandler = new AndroidPNSEntityHandler();
ArrayList<String> androidDeviceIds = androidPNSEntityHandler.getList();
/* I checked by adding only one device token to this arraylist like
this **androidDeviceIds.add("Android-Device-Token");**
It worked fine...
*/
if(androidDeviceIds.size() != 0)
{
String title;
if(!isOrangeCall)
title = "title";
else
title = "oTitle";
Message message = new Message.Builder()
.collapseKey(pnsCollapseKey)
.timeToLive(86400)
.addData(title,msgTitle)
.addData("content",msgContent)
.build();
try
{
MulticastResult result = sender.send(message, androidDeviceIds, 5);
if (result.getResults() != null)
{
int failureMsgs = result.getFailure();
int canonicalRegId = result.getCanonicalIds();
List<Result> multicastResults = result.getResults();
Boolean flag =true;
int total;
if(failureMsgs != 0 || canonicalRegId != 0)
{
for(total = 0;flag;total++)
{
if(canonicalRegId != 0)
{
String tempCanId = multicastResults.get(total).getCanonicalRegistrationId();
if( tempCanId != null)
{
if(androidPNSEntityHandler.deleteDuplicate(androidDeviceIds.get(total), tempCanId))
canonicalRegId--;
}
}
if(failureMsgs != 0)
{
if(multicastResults.get(total).getErrorCodeName().equals(Constants.ERROR_NOT_REGISTERED))
{
if(androidPNSEntityHandler.deleteUid(androidDeviceIds.get(total)));
failureMsgs--;
}
}
if(canonicalRegId == 0 && failureMsgs == 0)
flag = false;
}
}
}
}catch (java.lang.IllegalArgumentException e)
{
e.printStackTrace();
}catch (InvalidRequestException e)
{
e.printStackTrace();
}catch (java.io.IOException e)
{
e.printStackTrace();
}catch (Exception e)
{
e.printStackTrace();
}
}
请指导我解决这个问题...
答案 0 :(得分:0)
docs非常清楚1000是限制:
registration_ids
接收设备列表(注册ID)的字符串数组 消息。它必须包含至少1 且至多1000 注册ID。要发送多播消息,您必须使用JSON。对于 向单个设备发送单个消息,您可以使用JSON 只有1个注册ID或纯文本的对象(见下文)。 必需的。