App集成极光推送开发流程[关键步骤]
1.客户端集成SDK
1.1初始化
JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
JPushInterface.init(this); // 初始化 JPush
1.2设置别名及标签
//设置别名(如果已设置,则无需重新设置),存储别名保存状态
SharedPreferences mySharedPreferences = getSharedPreferences("test",Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mySharedPreferences.edit();
boolean hasSetTagAlias = mySharedPreferences.getBoolean("hasSetTagAlias",false);
if(!hasSetTagAlias){
JPushUtil.setTag(LoginActivity.this,mDepartment.substring(0,12));
JPushUtil.setAlias(LoginActivity.this,userId.replaceAll("-","_"));
editor.putBoolean("hasSetTagAlias", true);
}
2.服务端集成SDK
2.1导入依赖jar包(Maven项目配置pom.xml文件即可)

2.2构造通送内容,发起推送
/**
* 别名推送
* @param alert 推送标题
* @param ticketId 点击通知进入的工单id
* @param alias 推送给指定的别名(以用户的id为别名)
*/
public static void pushByAlias(String alert,String ticketId,String alias){
JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, ClientConfig.getInstance());
// For push, all you need do is to build PushPayload object.
PushPayload payload = PushPayload.newBuilder().setPlatform(Platform.all())
.setAudience(Audience.all())
.setNotification(Notification.newBuilder()
.addPlatformNotification(AndroidNotification.newBuilder()
.setAlert(alert)
.addExtra("id", ticketId)
.build())
.build())
.setAudience(Audience.newBuilder()
.addAudienceTarget(AudienceTarget.alias(alias))
.build())
.build(); try {
PushResult result = jpushClient.sendPush(payload);
logger.info("Got result - " + result); } catch (APIConnectionException e) {
// Connection error, should retry later
logger.error("Connection error, should retry later", e); } catch (APIRequestException e) {
// Should review the error, and fix the request
logger.error("Should review the error, and fix the request", e);
logger.info("HTTP Status: " + e.getStatus());
logger.info("Error Code: " + e.getErrorCode());
logger.info("Error Message: " + e.getErrorMessage());
}
}
/**
* 标签推送
* @param alert 推送标题
* @param ticketId 点击通知进入的工单id
* @param alias 推送给指定的别名(以用户的id为别名)
*/
public static void pushByTag(String alert,String ticketId,String tag){
JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, ClientConfig.getInstance());
// For push, all you need do is to build PushPayload object.
PushPayload payload = PushPayload.newBuilder().setPlatform(Platform.all())
.setAudience(Audience.all())
.setNotification(Notification.newBuilder()
.addPlatformNotification(AndroidNotification.newBuilder()
.setAlert(alert)
.addExtra("id", ticketId)
.build())
.build())
.setAudience(Audience.newBuilder()
.addAudienceTarget(AudienceTarget.tag(tag))
.build())
.build(); try {
PushResult result = jpushClient.sendPush(payload);
logger.info("Got result - " + result); } catch (APIConnectionException e) {
// Connection error, should retry later
logger.error("Connection error, should retry later", e); } catch (APIRequestException e) {
// Should review the error, and fix the request
logger.error("Should review the error, and fix the request", e);
logger.info("HTTP Status: " + e.getStatus());
logger.info("Error Code: " + e.getErrorCode());
logger.info("Error Message: " + e.getErrorMessage());
}
}
App集成极光推送开发流程[关键步骤]的更多相关文章
- App集成极光推送步骤
一.准备: 1.1注册极光开发者账号 1.2添加应用,获取AppKey 1.3下载提供的demo,demo中的AppKey已自动生成为你自己的AppKey 二.集成: 2.1第一种方式:自动集成 Mo ...
- C#—ASP.NET:集成极光推送(Push API v3)
C#—ASP.NET:集成极光推送(Push API v3) 原文地址: https://blog.csdn.net/CXLLLK/article/details/86489994 1.极光推送官 ...
- 李洪强iOS之集成极光推送三iOS集成指南
李洪强iOS之集成极光推送三iOS集成指南 SDK说明 适用版本 本文匹配的 SDK版本:r2.1.5 以后.查看最近更新了解最新的SDK更新情况.使用Xcode 6及以上版本可以使用新版Push S ...
- 李洪强iOS之集成极光推送二iOS 证书 设置指南
李洪强iOS之集成极光推送二iOS 证书 设置指南 创建应用程序ID 登陆 iOS Dev Center 选择进入iOS Provisioning Portal. 在 iOS Provisioning ...
- 李洪强iOS之集成极光推送一iOS SDK概述
李洪强iOS之集成极光推送一iOS SDK概述 JPush iOS 从上图可以看出,JPush iOS Push 包括 2 个部分,APNs 推送(代理),与 JPush 应用内消息. 红色部分是 A ...
- Android集成极光推送
要说学习极光推送,个人感觉官方文档就非常好啦,但是没法,人太懒啦,为了下次能够快速的将极光推送集成到项目中,故结合之前开发的项目和官方文档记录下简单的Android集成极光推送,在这之前,先上一张简单 ...
- 1、Android Studio集成极光推送(Jpush) 报错 java.lang.UnsatisfiedLinkError: cn.jpush.android.service.PushProtoco
Android studio 集成极光推送(Jpush) (华为手机)报错, E/JPush: [JPushGlobal] Get sdk version fail![获取sdk版本失败!] W/Sy ...
- Swift3集成极光推送
现在很多程序都开始使用Swift开发了,但是第三方库大多数都是用OC写的,所以我们要使用Swift和OC混编.今天的内容主要讲Swift3.0集成极光推送. 1.准备工作 集成指南,极光上说的 ...
- ThinkPHP 3.2.x 集成极光推送指北
3.2版本已经过了维护生命周期,官方已经不再维护,请及时更新至5.0版本 -- ThinkPHP 官方仓库 以上,如果有条件,请关闭这个页面,然后升级至 ThinkPHP 5,如果由于各种各样的原因无 ...
随机推荐
- Victor/ArrayList/LinkedList/Stack/CopyOnWriteArrayList 区别
Victor:采用数组的方式存储数据,与ArrayList相同,线程安全.性能比ArrayList差 ArrayList:采用数据的方式存储数据,线程不安全.ArrayList使用数组来存储数据,使用 ...
- Codeforces 577B Modulo Sum:数学 结论【选数之和为m的倍数】
题目链接:http://codeforces.com/problemset/problem/448/C 题意: 给你n个数字,给定m. 问你是否能从中选出若干个数字,使得这些数字之和为m的倍数. 题解 ...
- HDU 4714 Tree2cycle:贪心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4714 题意: 给你一棵树,添加和删除一条边的代价都是1.问你将这棵树变成一个环的最小代价. 题解: 贪 ...
- Delpih - Format
Format是一个很常用,却又似乎很烦的方法,本人试图对这个方法的帮助进行一些翻译,让它有一个完整的概貌,以供大家查询之用: 首先看它的声明:function Format(const Format: ...
- Java_基础_02_ThreadLocal
二.参考资料 1.ThreadLocal 那点事儿 2.彻底理解ThreadLocal
- CTreeCtrl控件
一.HTREEITEM HTREEITEM是树中节点的句柄,也就是一个DWORD值.在树中唯一标识一个节点.它的值对于程序员其实没有什么意义,只是可以通过它找到一个节点,从而取得节点的属性,如 Get ...
- STL stl_config.h
stl_config.h . // Filename: stl_config.h . . // Comment By: 凝霜 . // E-mail: mdl2009@vip.qq.com . // ...
- python实现无序列表:链表
介绍链表前我们先了解下什么是列表. 在对基本数据结构的讨论中,我们使用 Python 列表来实现所呈现的抽象数据类型.列表是一个强大但简单的收集机制,为程序员提供了各种各样的操作.然而,不是所有的编程 ...
- Gym 100801J Journey to the "The World's Start"(二分+单调队列)
题意: 现在有1,2,3...N这N个站, 给定限定时间Limt, N-1种票的价格, 分别对应一个最远距离, 叫你选择一种票, 满足可以在规定时间到达N站台,而且价格最低 思路: 如果买距离为L ...
- ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)
Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often ...