0

几天前,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();
    }
}

请指导我解决此问题...

4

1 回答 1

0

文档 清楚地表明 1000 是限制:

注册ID

A string array with the list of devices (registration IDs) receiving the message. It must contain at least 1 and at most 1000 registration IDs. To send a multicast message, you must use JSON. For sending a single message to a single device, you could use a JSON object with just 1 registration id, or plain text (see below). Required.

于 2012-10-29T16:03:00.010 回答