现在的位置: 首页 > 综合 > 正文

java利用极光推送进行推送的代码

2018年04月21日 ⁄ 综合 ⁄ 共 1159字 ⁄ 字号 评论关闭

今天学了推送的相关知识,记录下,以免忘记

<span style="white-space:pre">	</span>1.所有平台
	PushPayload payload = PushPayload payload = PushPayload.newBuilder()
									.setPlatform(Platform.all())
									.setAudience(Audience.alias("alias"))
									.setNotification(Notification.alert("测试推送"))
									.build();

	2.Android平台
	PushPayload payload = PushPayload payload = PushPayload.newBuilder()
									.setPlatform(Platform.android())
									.setAudience(Audience.alias("alias"))
									.setNotification(Notification.android("测试推送"))
									.build();

	3.ios平台
	PushPayload payload = PushPayload.newBuilder()
					                .setPlatform(Platform.ios())
					                .setAudience(Audience.tag("tag1"))
					                .setNotification(Notification.newBuilder()
					                        .addPlatformNotification(IosNotification.newBuilder()
					                                .setAlert("测试推送-ios")
					                                .setBadge(5)
					                                .setSound("happy")
					                                .addExtra("from", "JPush")
					                                .build())
					                        .build())
					                 .setMessage(Message.content("测试推送-content-ios"))
					                 .setOptions(Options.newBuilder()
					                         .setApnsProduction(true)
					                         .build())
					                 .build();

其中
Platform.xx():可以选择对应的平台
Audience.xx():可以选择对应的推送目标
alias("xxxx"):推送目标为别名为xxxx的目标
tag("xxxx"):推送目标为标签为xxxx的目标
tag_and("x1","x2"):推送目标为拥有x1,x2标签的目标
Notification.android(""):向安卓平台推送
Notification.ios(""):向ios平台推送
addExtra("",""):设定key/value信息,以供业务使用

另外这篇文章写得不错http://www.cnblogs.com/jiqing9006/p/3945095.html

抱歉!评论已关闭.