Google Cloud Messaging (Android 消息推送技术) (二)

 (一) 在上一章,我们提到Android 消息推送的基本流程和需要的几个键值。

这里介绍一下怎样使用Google Cloud Messaging (GCM)。

对于GCM的实现,google 早期使用的接口可以参考这篇文章。文章中已经充分介绍了在老接口下怎样实现GCM。

http://blog.csdn.net/huangjialiang1986/article/details/8056221

下面是对这篇文章代码的部分更改:

Android 客户端的代码为:

https://github.com/yuxiaohui78/Google_Cloud_Messaging/tree/master/GCMClientOnMobile_deprecated_version

模拟第三方服务器的消息发送部分代码:

https://github.com/yuxiaohui78/Google_Cloud_Messaging/tree/master/GCMSendOnPC


(二)由于google已经决定废弃老接口。所以下面我们来介绍一下新接口怎样实现。

新的Api接口需要google service 3.1+ 的支持。

1.在AndroidManifest.xml 中增加支持,允许接收云消息com.google.android.c2dm.permission.RECEIVE

<manifest package="com.example.gcm" ...>

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission android:name="com.example.gcm.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />

    <application ...>
        <receiver
            android:name=".GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值