项目中用到消息推送,要用到Google的GCM推送,就简单的记录一下:
参考地址:http://www.windowsazure.cn/documentation/services/mobile-services/
一、
下载并导入需要的jar包:mobileservices-2.0.3.jar 、 guava-17.0.jar 、 notifications-1.0.1.jar
二、
在启动的Activity中加入以下代码:
其中PushAppUrl 是服务端集成给出的
PushAppKey 是在Google控制台申请的
<span style="font-size:14px;"> public static MobileServiceClient mClient;
try {
mClient = new MobileServiceClient(Constants.PushAppUrl, Constants.PushAppKey, this);
} catch (MalformedURLException e) {
e.printStackTrace();
}</span>
三、注册并接受推送过来的消息
NotificationsManager.handleNotifications(getActivity(),
Constants.SENDER_ID, MyNotificationHandler.class);