SMP3.0学习笔记之十八 实现GCM的消息推送

来源:互联网 发布:淘宝评价了怎么看不到 编辑:程序博客网 时间:2024/05/21 18:40

作者:穿行印象 

http://blog.sina.com.cn/s/blog_7a9486880101qsjj.html


SMP3.0可以实现对iOS、BB、Android和WP移动设备的消息推送。这里以Android的Google Cloud Messaging为例说明SMP3.0的消息推送机制。

    首先对SMP Application的Android GCM进行配置:

    

API Key和Sender ID可以从Google获取。

在自己的Kapsel项目里增加Kapsel push Plugin:

cd C:\Kapsel_Projects\MyPushExcercise

cordova -d platform add android

cordova -d plugin add C:\SAP\MobileSDK3\KapselSDK\plugins\push

 

在代码中注册GCM客户端:

 

 registerForPush : function() {

        //TODO: Add push registration code

        var nTypes = sap.Push.notificationType.SOUNDS | sap.Push.notificationType.ALERT;

        sap.Push.registerForNotificationTypes(nTypes,

                                              this.registerForPushSuccess,

                                              this.registerForPushFailure,

                                              this.proccessNotification,

                                              "xxxxxx");  //GCM Sender ID, null for APNS

 

    },

 

移动成功Logon之后,使用Postman通过SMP向客户端发送GCM消息:

URL:

http://localhost:8080/Notification/490aeb6b-ddb0-46b4-8655-973c616009a4

490aeb6b-ddb0-46b4-8655-973c616009a4是移动设备登录SMP3.0之后的application ID。

使用POST方法。Header中增加X-SMP-GCM-DATA:

{"dispmsg":"Hello GCM Message!","appid":"com.sap.flight.kapsel","appname":"com.sap.flight.kapsel","reasonurl":"http://www.sap.com","reasoncode":12345}

红色字体部分为发送的GCM消息内容。Postman的截图:



消息发送后,系统终端收到如下消息并显示:


0 0