`
sillycat
  • 浏览: 2551378 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

GCM(2)GCM Demo Application

 
阅读更多
GCM(2)GCM Demo Application

This demo consists of the following pieces:

1. A web server containing a page where you can send messages

2. An Android application that receives and displays such messages.



Setting Up GCM in the GCM(1) blog.



Setting Up the Server
…snip...



Using App Engine for Java
Long time since I last play with app engine, https://appengine.google.com.



1. From the SDK Manager, install Extras> Google Cloud Messaging for Android Library



2. The sample project is under this directory

/opt/android-sdk/extras/google/gcm/samples/gcm-demo-appengine





Setting Up the Device
The client demo is here.

/opt/android-sdk/extras/google/gcm/samples/gcm-demo-client





Error Message:
[C2DMReg] handleRequest caught javax.net.ssl.SSLException: Not trusted server certificate



javax.net.ssl.SSLException: Not trusted server certificate

at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshacke

at android.net.SSLCertificateSocketFactory.verifyHostname



Error Message:
Intent service name: GCMIntentService-1044806436104-1

GCMRegistrar internal error: retry receiver class not set yet.

GCMBaseIntentService handleRegistration: registrationId = null, error = SERVICE_NOT_AVAILABLE, unregistered = null



Solution:
The problem is not code related, but link to the test phone. The test phone do not have a SIM, and the clock was not set. There is a wrong time there.



Error Message on Server Side:
com.google.android.gcm.demo.server.SendMessageServlet sendSingleMessage: Exception posting Message()
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.demo.server.SendMessageServlet.sendSingleMessage(SendMessageServlet.java:88)
at com.google.android.gcm.demo.server.SendMessageServlet.doPost(SendMessageServlet.java:68)
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:266)
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:146)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:447)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461)
at com.google.tracing.TraceContext.runInContext(TraceContext.java:703)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:338)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:330)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
  at java.lang.Thread.run(Thread.java:679)



Solution:
It store an old wrong key in the database, just delete it and replace with this new key.

Key for server apps (with IP locking).





Error Message while I am using the emulator:
java.lang.unsupportedoperationexception device does not have package com.google.android.gsf



Solution:
The virtual device I create has no GOOGLE API support. I will create another AVD.



I made the demo works in my own projects 4mymessage and EasyRestClientAndroid.



And I change some point from the original example:



1. That is the content sent by server side

Message message = new Message.Builder().addData("message",
"Message I want you to know.").build();



I change the Message.Builder to carry some customized message, and this message can be replaced by my business logic part.


2. How to receive and display the customized message
On the client side
protected void onMessage(Context context, Intent intent) {
     Log.i(TAG, "Received message");
     String message = getString(R.string.gcm_message);

     String extra_message = intent.getStringExtra("message");
     message = message + extra_message;

     displayMessage(context, message);
     // notifies user
     generateNotification(context, message);
}



We can get the message from getStringExtra method.


References:
https://developer.android.com/google/gcm/demo.html



http://sillycat.iteye.com/blog/586786

http://sillycat.iteye.com/blog/586787

http://sillycat.iteye.com/blog/770453

http://sillycat.iteye.com/blog/774529

http://sillycat.iteye.com/blog/774534

http://sillycat.iteye.com/blog/772524



http://www.techques.com/question/1-5104500/javax.net.ssl.SSLHandshakeException:-Could-not-verify-SSL-certificate-for:-https:--android.apis.google.com-c2dm-send



http://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https



http://stackoverflow.com/questions/2012497/accepting-a-certificate-for-https-on-android



http://androidmyway.wordpress.com/2012/07/09/gcm-demo/



http://stackoverflow.com/questions/11398470/google-cloud-messaging-gcm-service-not-available



http://android.amolgupta.in/2012/07/google-cloud-messaging-gcm-tutorial.html



http://stackoverflow.com/questions/11339445/com-google-android-gsf-package-couldnt-be-found
分享到:
评论

相关推荐

    built.io-android-gcm-push-demo:built.io 支持 iOS 和 Android 的通知。 在 Android 中,推送通知由 GCM(Google Cloud Messaging)服务提供。 要设置 GCM,请按照

    built.io-android-gcm-push-demo built.io 支持 iOS 和 Android 的通知。 在 Android 中,推送通知由 GCM(Google Cloud Messaging)服务提供。 要设置 GCM,请遵循: : 要开始此演示,您需要一个“Google API ...

    android 推送demo

    2. **初始化FCM**:在Application类或者合适的地方初始化FCM服务,注册接收器。 3. **获取设备令牌**:在FCM服务注册成功后,保存设备令牌供服务器使用。 4. **创建服务器端逻辑**:使用获取的服务器密钥和设备令牌...

    信鸽推送Demo

    "信鸽推送Demo"是一个基于信鸽推送服务的应用示例,旨在帮助开发者了解和学习如何在自己的应用程序中集成信鸽推送服务。信鸽推送是中国移动旗下的一个强大的消息推送平台,广泛应用于各种移动应用中,提供了高效、...

    进阶android源码demo

    2. **组件通信机制**:Android四大组件(Activity、Service、BroadcastReceiver、ContentProvider)之间的交互是通过Intent进行的。通过源码,你可以看到Intent是如何在组件间传递信息,以及如何触发相应的操作。 3...

    Android之激光推送客户端demo源码.zip

    在Android平台上,Google提供了GCM(Google Cloud Messaging)和其继任者FCM(Firebase Cloud Messaging)来实现这一功能,但开发者也可以选择第三方服务,如LaserPush,以获得更定制化的解决方案。 LaserPush...

    融云的使用demo

    融云支持APNs(Apple Push Notification service)和GCM(Google Cloud Messaging)等推送服务,确保即使应用在后台,用户也能接收到新消息的通知。 7. **语音与视频通话**: 融云的语音和视频通话功能是通过`RTC...

    Android高级应用源码-激光推送客户端demo.zip

    激光推送客户端的实现主要依赖于GCM(Google Cloud Messaging)或者FCM(Firebase Cloud Messaging),这是Google提供的云端到设备的消息推送服务。 二、核心组件解析 1. 应用注册:在应用启动时,客户端会注册到...

    安卓Android源码——激光推送客户端demo.zip

    2. **初始化SDK**:在应用启动时,需要调用激光推送提供的初始化方法,通常在`Application` 类的`onCreate()` 方法中完成。这一步会设置App的唯一标识符和必要的API密钥。 3. **注册设备令牌**:当应用首次启动或者...

    Android-基于BmobPushSDK开发的官方Android版示例

    2. **注册设备**:获取设备的唯一标识(如GCM的registrationId或华为、小米等厂商的token),并将其注册到Bmob服务器。 3. **接收推送**:创建一个继承自`BroadcastReceiver`的类,重写`onReceive`方法,解析推送...

    个推sdk的接入流程

    当应用获得系统推送服务的deviceToken(Android的GCM Registration ID或iOS的APNs Token)后,需通过个推SDK的接口将deviceToken上传至个推服务器。这样,个推才能识别到该设备并进行消息推送。 4. **设置接收消息...

Global site tag (gtag.js) - Google Analytics