2012-07-19 61 views
2

我能夠從android設備註冊到appengine 一旦我註冊了appengine,我就得到了android應用上的registrationId。 使用registrationId我試圖從appengine服務器發送消息到android應用程序。從Appengine發送gcm push到android

Sender sender = new Sender(App-Key); 
Message message = new Message.Builder().addData("data", "hello client").build(); 
Result result = sender.send(message, registrationId , 5); 

我已經將上面的代碼嵌入到http post方法中。

,但我得到以下錯誤:

Uncaught exception from servlet 
com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401 
    at com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177) 
    at com.google.android.gcm.server.Sender.send(Sender.java:121) 
    at com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServlet.java:86) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) 
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) 
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) 
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) 
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:249) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at org.mortbay.jetty.Server.handle(Server.java:326) 
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) 
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) 
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76) 
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135) 
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:477) 
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:449) 
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:455) 
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:695) 
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:333) 
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:325) 
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:453) 
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251) 

誰能幫我解決這個問題。

Sender sender = new Sender(App-Key); 
Message message = new Message.Builder().build(); 
Result result = sender.send(message, registrationId , 5); 

多個Android設備:

回答

0

我已經做如下修改代碼

單一Android設備解決了該問題

Sender sender = new Sender(App-Key); 
Message message = new Message.Builder().build(); 
MulticastResult result = sender.send(message, list of registrationIds , 5); 

然而通知轉到Android設備從Appengine,但我仍然想知道如何將消息發送到Android設備以及通知。

+0

你好,在這裏你提到MulticastResult結果= sender.send(消息,registrationIds的名單,5); 所以,registrationIds列表是列表? – Dev 2015-01-19 20:15:31