<p>Amazon SNS 的实现的流程图如下(网址 <a href="http://docs.aws.amazon.com/sns/latest/dg/SNSMobilePush.html">http://docs.aws.amazon.com/sns/latest/dg/SNSMobilePush.html</a>):</p> <p><a href="http://static.oschina.net/uploads/img/201308/23133717_nWoC.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://static.oschina.net/uploads/img/201308/23133743_Xzdt.png" width="574" height="152" /></a> </p> <p>以上流程图是向移动设备发送message的一个流程,SNS服务其实也是利用别的平台(如下),来达到向不同的设备推送消息的功能。</p> <ul> <li> <p>苹果推送通知服务(APNS)</p> </li> <li> <p>谷歌为Android云通讯(GCM)</p> </li> <li> <p>亚马逊设备消息(ADM)</p> </li> </ul> <p></p> <p>我们怎么获得这个服务呢?</p> <ol> <li>下载Amazon AWS 提供的代码样例(<a title="https://s3.amazonaws.com/codesamples/sns/latest/snsmobilepush.zip" href="https://s3.amazonaws.com/codesamples/sns/latest/snsmobilepush.zip">https://s3.amazonaws.com/codesamples/sns/latest/snsmobilepush.zip</a>) </li> <li>获得你的AWS 的证书,包含两个内容accessKey和secretKey(<a title="http://aws.amazon.com/security-credentials" href="http://aws.amazon.com/security-credentials">http://aws.amazon.com/security-credentials</a>),填入样例代码\snsmobilepush\SNSSamples\src\com\amazonaws\sns\samples\mobilepush\AwsCredentials.properties中对应的位置。若不知道怎么获取,请看 <h3><a href="http://docs.aws.amazon.com/general/latest/gr/getting-aws-sec-creds.html">How Do I Get Security Credentials?</a></h3> </li> <li>以向普通的Android手机发送Message为例,我们会用到GCM(<a href="http://developer.android.com/google/gcm/index.html">http://developer.android.com/google/gcm/index.html</a>),然后我们按着Amazon文档所说(<a href="http://docs.aws.amazon.com/sns/latest/dg/mobile-push-gcm.html">http://docs.aws.amazon.com/sns/latest/dg/mobile-push-gcm.html</a>)进行操作: </li> </ol> <blockquote> <p>客户端:样例代码需要一个project ID,这个在<a href="https://code.google.com/apis/console">google API console</a>上申请获得(在Service中将GCM for Android服务开启,另外还会有一个API密钥,会在你自己的service端用到),然后运行程序,会获得一个registerID(会在你自己的service端用到,正常的流程应该要程序自己将ID发给service,在样例中要自己拷贝到服务程序)</p> <p>ps:需要Android 2.2以上,并装有google Play,并且有账号登入,模拟器的话,要有google API。</p> <p>服务器端:会用到<a href="https://code.google.com/apis/console">google API console</a>提到的API密钥,registerID,你的程序名,解开SNSMobilePush.java中注释掉的//sample.demoAndroidAppNotification(Platform.GCM);</p> <p>对于服务器端的代码中用到的API的解释,请点击(<a href="http://docs.aws.amazon.com/sns/latest/dg/mobile-push-api.html">http://docs.aws.amazon.com/sns/latest/dg/mobile-push-api.html</a>)。</p></blockquote>