`

Android Cloud to Device Messaging Framework(三)

 
阅读更多

Developing and Testing Your Applications

下面是给开发和测试使用C2DM的程序的一些建议:

1.    要开发和测试C2DM程序。你需要在Android2.2的设备上运行和调试这个程序。这个设备包含基本的google服务。

2.    要在真机上面开发和调试,真机必须是Android2.2并且包含Market

3.    要在模拟器上开发和调试,需要下载Android2.2 SDKGoogle APIs by Google IncAndroid API 8。然后建模拟器的时候选择google api 8

4.    如果C2DM对程序是一个至关重要的功能,必须在AndroidManifest.xml里设置android:minSdkVersion=”8”。确保程序装在能使程序正常运行的环境里。

Role of the Third-Party Application Server

在你写一个使用C2DM的程序之前,你必须有一个HTTPS 程序服务器并满足下面的要求:

1.    可以和客户端通信

2.    可以对C2DM服务器发起HTTP请求

3.    可以处理请求并可以按需要排列消息。比如,可以执行指数退避。

4.    可以存储ClientLogin Auth Tokenregistration IDsClientLogin Auth Token包含在发送消息的Postheader里。更多关于ClientLogin,看这里ClientLogin for Installed Applications。服务器端具有存储token的能力并可定期的刷新。

How the Application Server Sends Messages

这一节主要讲第三方程序服务器怎么发送消息到手机上的第三方程序。在第三方程序服务器可以发送消息给程序以前,它必须收到registration ID

要发送消息,第三方程序服务器要发起一个post请求到https://android.apis.google.com/c2dm/send 并包含以下参数:

Field

Description

registration_id

必须参数。手机上的程序发过来的registration ID

collapse_key

必须参数。当手机离线的时候,一个任意的字符串用来处理一组消息,这样的话只有最后一条消息可以到客户端。这是为了避免发送大量的消息到客户端当手机重新在线的时候。不能保证消息的顺序,所以发送到客户端的消息不一定是第三方服务器发送的最后一条。

data.<key>

可选参数。消息。用键值对表达。如果存在,会被作为数据包含在Intent中,对应key。 对于键值对的数目没有限制。但是对总的数据大小是有限制的。

delay_while_idle

可选参数。如果使用,表示当手机闲置的时候,消息不需要立即发送。服务器会等手机重新在线,然后发送每一个collapse_key的最后一条消息。

Authorization: GoogleLogin auth=[AUTH_TOKEN]

必须参数。ClientLogin Auth Token作为header. Cookie必须和ac2dm关联。

服务器响应:

Response

Description

200

Includes body containing:

·         id=[ID of sent message]

·         Error=[error code]

o    QuotaExceeded — sender发送了太多的消息。稍后重试。

o    DeviceQuotaExceeded — 太多的消息发往某个手机. 稍后重试。

o    InvalidRegistration — 缺少或者无效的registration_id. Sender应该停止发送消息到这个手机。

o    NotRegistered —registration_id无效, 比如用户卸载了程序或者关闭了通知。Sender应该停止发送消息到这个手机。

o    MessageTooBig — 消息太大,减少消息的大小。 MissingCollapseKey — 没有collapse key。在请求里包含collapse key

503

表明服务器暂时不可连接. Sender must retry later, honoring any Retry-After header included in the response. Application servers must implement exponential back off. Senders that create problems risk being blacklisted.

401

表明用于验证senderClientLogin Auth Token无效。

Limitations

C2DM有下面的限制:

1.    消息大小的限制:1024bytes

2.    Google限制了sender发送消息的总数和sender发送消息到某个手机的总数。

分享到:
评论

相关推荐

    C2DM (Android Cloud to Device Messaging)

    Android Cloud to Device Messaging Framework

    Android 4高级编程(第3版)

    ◆ 解释了如何创建后台服务、通知和Cloud to Device Messaging ◆ 演示了如何创建动态的、交互式的主屏幕微件和Live Wallpaper ◆ 探索了硬件和通信API,包括蓝牙、电话、Wi-Fi Direct、 NFC和Android Beam ◆ 讲解...

    Android代码-Odoo Messaging

    Odoo Mobile Client is Enterprise Social Client based on Android, enables you to access your Odoo Wall Messages from inbox and groups, encourage you to updated with companies' current activities for ...

    Professional Android 4 Application Development 源代码

    Introducing Cloud to Device Messaging Implementing Copy Protection Using the License Verification Library Introducing In-App Billing Using Wake Locks Using AIDL to Support Inter-Process Communication ...

    Android 4高级编程(第3版).pdf 高清

    解释了如何创建后台服务、通知和Cloud to Device Messaging;演示了如何创建动态的、交互式的主屏幕微件和Live Wallpaper;探索了硬件和通信API,包括蓝牙、电话、Wi-Fi Direct、NFC和Android Beam;讲解了摄像头和...

    JAVA实现阿里百川-推送消息

    最近项目需要消息推送功能,由于 Android 谷歌官方的服务C2DM(Android Cloud to Device Messaging ) 由于'墙'的原因在国内不能正常使用,而且自己集成搭建自己的服务器代价相对比较大,而且,会出现一系列的问题。...

    Simple Messaging Framework-开源

    简单消息框架提供了一种创建健壮且灵活的Web服务的优雅方法。 它基于文档样式的Web服务范例,使您能够轻松公开任意复杂的业务对象和服务。

    Professional Android 4 Application Development

    Looks at how to create background services, Notifications, and Cloud To Device Messaging Demonstrates how to create dynamic and interactive home screen Widgets and Live Wallpaper Explores hardware and...

    Android2.1消息应用(Messaging)源码学习笔记.pdf

    Android2.1消息应用(Messaging)源码学习笔记.pdf

    Android 4高级编程(第3版).part1

    ◆ 解释了如何创建后台服务、通知和Cloud to Device Messaging ◆ 演示了如何创建动态的、交互式的主屏幕微件和Live Wallpaper ◆ 探索了硬件和通信API,包括蓝牙、电话、Wi-Fi Direct、 NFC和Android Beam ◆ 讲解...

    Android 4高级编程(第3版).part2

    ◆ 解释了如何创建后台服务、通知和Cloud to Device Messaging ◆ 演示了如何创建动态的、交互式的主屏幕微件和Live Wallpaper ◆ 探索了硬件和通信API,包括蓝牙、电话、Wi-Fi Direct、 NFC和Android Beam ◆ 讲解...

    Android 4高级编程(第3版).part3

    ◆ 解释了如何创建后台服务、通知和Cloud to Device Messaging ◆ 演示了如何创建动态的、交互式的主屏幕微件和Live Wallpaper ◆ 探索了硬件和通信API,包括蓝牙、电话、Wi-Fi Direct、 NFC和Android Beam ◆ 讲解...

    Google-Cloud-Messaging--Titanium-, 在 Titanium 中,Google云消息传递.zip

    Google-Cloud-Messaging--Titanium-, 在 Titanium 中,Google云消息传递 Google-Cloud-Messaging--Titanium -注册带有GCM和处理发送到设备的通知的Titanium MODULE 。Android平台使用c2dm进行推送,但是因为c2dm停止...

    Android 4高级编程(第3版)源代码

     ◆ 解释了如何创建后台服务、通知和Cloud to Device Messaging  ◆ 演示了如何创建动态的、交互式的主屏幕微件和Live  Wallpaper  ◆ 探索了硬件和通信API,包括蓝牙、电话、Wi-Fi Direct、  NFC和Android ...

    fcm-django:FCM Django:通过django通过FCM(Firebase Cloud Messaging)将推送通知发送到网站,iOS和android移动设备

    fcm-django:FCM Django:通过django通过FCM(Firebase Cloud Messaging)将推送通知发送到网站,iOS和android移动设备

    Spring Boot Messaging

    You will learn and integrate these messaging APIs with more complex enterprise and cloud applications: for example, you will see how to use Spring Cloud Stream for creating message-driven and cloud ...

    spring-messaging-4.3.12.RELEASE-API文档-中英对照版.zip

    标签:springframework、spring、messaging、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和...

    Cloud.Native.Go

    The Complete Guide to Building Cloud-Based Services Cloud Native Go shows developers how to build massive cloud applications that meet the insatiable demands of today’s customers, and will ...

    spring-messaging-4.3.20.RELEASE-API文档-中文版.zip

    对应Maven信息:groupId:org.springframework,artifactId:spring-messaging,version:4.3.20.RELEASE 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中...

Global site tag (gtag.js) - Google Analytics