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,如果由于各种各样的原因无 ...
随机推荐
- R语言编程中的常见错误
R语言编程中的常见错误有一些错误是R的初学者和经验丰富的R程序员都可能常犯的.如果程序出错了,请检查以下几方面. 使用了错误的大小写.help().Help()和HELP()是三个不同的函数(只有第 ...
- delphi数据库的备份及还原
实例应用1: //备份procedure TF_DataBaseBackUp.Btn_bfClick(Sender: TObject); var i:integer; begin if SaveDia ...
- fatal error C1071: unexpected end of file found in comment
1.错误 #include<iostream> using namespace std; int main() { ..... return 0; } //如果把注释放到这里了,那么提交就 ...
- POJ1060 Modular multiplication of polynomials解题报告 (2011-12-09 20:27:53)
Modular multiplication of polynomials Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3 ...
- 如何用Mendeley引用目标期刊要求的参考文献格式
如果我们要向目标的杂志期刊投稿,则需要采用该期刊的参考文献格式.我用的mendeley管理文献,不收费且使用方便.那么,我们如何用mendeley引用目标期刊的参考文献呢?以Applied energ ...
- hdu2196 Computer待续
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #i ...
- bzoj2654tree
给定一个n个点m条边的图,每条边有黑白两色,求出恰好含need条白边的最小生成树 最小生成树...仿佛并没有什么dp的做法 大概还是个kruskal的板子再加点什么东西 考虑到“恰好含need条白边” ...
- Oracle 12c 多租户 CDB 与 PDB之 shared undo 与 Local undo 切换
undo 在12C R1版本中只支持Global Shared Undo模式, 所有container共享一个UNDO表空间, 目前保留这种模式只是为了升级过渡, 在12C R2引入了PDB Loca ...
- BZOJ1012:[JSOI2008]最大数
浅谈栈:https://www.cnblogs.com/AKMer/p/10278222.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?id ...
- BZOJ2212:[POI2011]Tree Rotation
浅谈线段树合并:https://www.cnblogs.com/AKMer/p/10251001.html 题目传送门:https://lydsy.com/JudgeOnline/problem.ph ...