- 浏览: 2551057 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
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
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
发表评论
-
ionic UI(4)ionic2 framework - basic and components and native
2016-03-24 02:33 1261ionic UI(4)ionic2 framework - b ... -
ionic UI(3)TypeScript - handbook
2016-03-22 23:21 634ionic UI(3)TypeScript - handboo ... -
ionic UI(2)ionic2 framework - TypeScript - tutorial
2016-03-22 06:52 1656ionic UI(2)ionic2 framework - T ... -
Parse and Heroku Service(3)Parse Server and Parse Dashboard
2016-03-22 06:30 967Parse and Heroku Service(3)Pars ... -
Parse and Heroku Service(2)Mail Templates and Push Notification
2016-03-22 02:45 583Parse and Heroku Service(2)Mail ... -
ionic UI(1)Introduction
2016-03-19 03:18 723ionic UI(1)Introduction 1 Inst ... -
Parse and Heroku Service(1)Heroku Installation and Play
2016-03-19 00:13 824Parse and Heroic Service(1)Hero ... -
Hybrid(5)Customize Meteor Directly Google Login
2015-09-01 02:33 910Hybrid(5)Customize Meteor Direc ... -
Hybrid(4)Favorite Places - Google Login
2015-09-01 02:02 1341Hybrid(4)Favorite Places - Goog ... -
Hybrid(3)More Meteor Example - Social
2015-08-11 05:04 756Hybrid(3)More Meteor Example - ... -
Hybrid(2)meteor Running Android and iOS
2015-07-28 23:59 1049Hybrid(2)meteor Running Android ... -
Create the Google Play Account
2015-07-18 06:42 1101Create the Google Play Account ... -
Secure REST API and Mobile(1)Document Read and Understand OAUTH2
2015-07-14 00:36 764Secure REST API and Mobile(1)Do ... -
Screen Size and Web Design
2015-07-11 01:11 725Screen Size and Web Design iPh ... -
Hybrid(1)ionic Cordova meteor
2015-06-25 05:49 471Hybrid(1)ionic Cordova meteor ... -
Android Fire Project(1)Recall Env and Knowledge
2015-02-11 12:28 686Android Fire Project(1)Recall ... -
Android Content Framework(1)Concept
2014-06-14 13:54 1080Android Content Framework(1)Con ... -
Feel Android Studio(1)Install and Update Android Studio
2014-04-11 03:12 2029Feel Android Studio(1)Install a ... -
IOS7 App Development Essentials(2)iBeacon
2014-03-05 05:55 890IOS7 App Development Essentials ... -
IOS7 App Development Essentials(1) Persistent Store
2014-03-05 05:54 1327IOS7 App Development Essentials ...
相关推荐
built.io-android-gcm-push-demo built.io 支持 iOS 和 Android 的通知。 在 Android 中,推送通知由 GCM(Google Cloud Messaging)服务提供。 要设置 GCM,请遵循: : 要开始此演示,您需要一个“Google API ...
2. **初始化FCM**:在Application类或者合适的地方初始化FCM服务,注册接收器。 3. **获取设备令牌**:在FCM服务注册成功后,保存设备令牌供服务器使用。 4. **创建服务器端逻辑**:使用获取的服务器密钥和设备令牌...
"信鸽推送Demo"是一个基于信鸽推送服务的应用示例,旨在帮助开发者了解和学习如何在自己的应用程序中集成信鸽推送服务。信鸽推送是中国移动旗下的一个强大的消息推送平台,广泛应用于各种移动应用中,提供了高效、...
2. **组件通信机制**:Android四大组件(Activity、Service、BroadcastReceiver、ContentProvider)之间的交互是通过Intent进行的。通过源码,你可以看到Intent是如何在组件间传递信息,以及如何触发相应的操作。 3...
在Android平台上,Google提供了GCM(Google Cloud Messaging)和其继任者FCM(Firebase Cloud Messaging)来实现这一功能,但开发者也可以选择第三方服务,如LaserPush,以获得更定制化的解决方案。 LaserPush...
融云支持APNs(Apple Push Notification service)和GCM(Google Cloud Messaging)等推送服务,确保即使应用在后台,用户也能接收到新消息的通知。 7. **语音与视频通话**: 融云的语音和视频通话功能是通过`RTC...
激光推送客户端的实现主要依赖于GCM(Google Cloud Messaging)或者FCM(Firebase Cloud Messaging),这是Google提供的云端到设备的消息推送服务。 二、核心组件解析 1. 应用注册:在应用启动时,客户端会注册到...
2. **初始化SDK**:在应用启动时,需要调用激光推送提供的初始化方法,通常在`Application` 类的`onCreate()` 方法中完成。这一步会设置App的唯一标识符和必要的API密钥。 3. **注册设备令牌**:当应用首次启动或者...
2. **注册设备**:获取设备的唯一标识(如GCM的registrationId或华为、小米等厂商的token),并将其注册到Bmob服务器。 3. **接收推送**:创建一个继承自`BroadcastReceiver`的类,重写`onReceive`方法,解析推送...
当应用获得系统推送服务的deviceToken(Android的GCM Registration ID或iOS的APNs Token)后,需通过个推SDK的接口将deviceToken上传至个推服务器。这样,个推才能识别到该设备并进行消息推送。 4. **设置接收消息...