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()); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2016-10-25 Eclipse与IntelliJ IDEA区别
2015-10-25 oracle数据库自动备份脚本