极光推送 android 最新,android 接极光推送

本文档详细介绍了如何在Android应用中配置并使用JPush极光推送服务,包括在build.gradle文件中添加依赖,自定义接收器处理推送消息,以及在AndroidManifest.xml中设置服务。通过这些步骤,开发者可以实现应用的推送通知和自定义消息的接收与处理。
摘要由CSDN通过智能技术生成

步骤 1 在app 的build.gradle

// 极光相关配置

manifestPlaceholders = [

JPUSH_PKGNAME :applicationId,

JPUSH_APPKEY : JPUSH_APPKEY,

JPUSH_CHANNEL :"developer-default",//暂时填写默认值即可.

]

dependencies{

implementation'cn.jiguang.sdk:jpush:3.8.6' // 此处以JPush 3.8.6 版本为例。

implementation'cn.jiguang.sdk:jcore:2.6.0'  // 此处以JCore 2.6.0 版本为例。

}

2 在 androidmainfest.xml

android:name=".service.JPushIntentService"

android:enabled="true"

android:exported="false"

android:process=":pushcore">

新建 PushMessageReceiverextends

public class PushMessageReceiverextends JPushMessageReceiver {

private static final StringTAG ="JIGUANG";

/**

* TODO 连接极光服务器

*/

@Override

public void onConnected(Context context, boolean b) {

super.onConnected(context, b);

Log.e(TAG, "onConnected");

}

/**

* TODO 注册极光时的回调

*/

@Override

public void onRegister(Context context, String s) {

super.onRegister(context, s);

Log.e(TAG, "onRegister" + s);

}

/**

* TODO 注册以及解除注册别名时回调

*/

@Override

public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {

super.onAliasOperatorResult(context, jPushMessage);

Log.e(TAG, jPushMessage.toString());

}

/**

* TODO 接收到推送下来的通知

*      可以利用附加字段(notificationMessage.notificationExtras)来区别Notication,指定不同的动作,附加字段是个json字符串

*      通知(Notification),指在手机的通知栏(状态栏)上会显示的一条通知信息

*/

@Override

public void onNotifyMessageArrived(Context context, NotificationMessage notificationMessage) {

super.onNotifyMessageArrived(context, notificationMessage);

Log.e(TAG, notificationMessage.toString());

}

/**

* TODO 打开了通知

*      notificationMessage.notificationExtras(附加字段)的内容处理代码

*      比如打开新的Activity, 打开一个网页等..

*/

@Override

public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {

super.onNotifyMessageOpened(context, notificationMessage);

Log.e(TAG, notificationMessage.notificationExtras);

}

/**

* TODO 接收到推送下来的自定义消息

*      自定义消息不是通知,默认不会被SDK展示到通知栏上,极光推送仅负责透传给SDK。其内容和展示形式完全由开发者自己定义。

*      自定义消息主要用于应用的内部业务逻辑和特殊展示需求

*/

@Override

public void onMessage(Context context, CustomMessage customMessage) {

super.onMessage(context, customMessage);

Log.e(TAG, "onMessage");

JSONObject obj = JSON.parseObject(customMessage.message);

Logger.t("接收到的推送内容").json(JSON.toJSONString(obj));

}

}

新建 JPushIntentServiceextends

public class JPushIntentServiceextends JCommonService {

}

最后 确认下你的 根目录 build.gradle  是否有 jcenter 没有就加上

buildscript {

repositories {

jcenter()

}

......

}

allprojects {

repositories {

jcenter()

}

}

好了 代码就上面, 你要是拿到自定义消息   public void onMessage(Context context, CustomMessage customMessage) { }在这个里面写

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值