极光推送点击推送过来的消息跳转新的页面,返回以后重启APP

1.需要在继承JPushMessageReceiver的服务类里修改onNotifyMessageOpened方法里的代码块,自己定义一个通知

class MyService : JPushMessageReceiver() {
    override fun onAliasOperatorResult(p0: Context?, p1: JPushMessage?) {
        super.onAliasOperatorResult(p0, p1)
        LogUtil.e(p1.toString())
    }

    override fun onMessage(p0: Context?, p1: CustomMessage?) {
        super.onMessage(p0, p1)

    }

    override fun onNotifyMessageOpened(context: Context?, message: NotificationMessage?) {
        LogUtil.e(message.toString())
        try {
            //打开自定义的Activity
            val intent = Intent(context, NotificationReportDetailsActivity::class.java)
            val bundle = Bundle()
            bundle.putString(JPushInterface.EXTRA_ALERT, message?.notificationExtras)
            intent.putExtras(bundle)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            val CHANNEL_ID = "my_channel"
            val builder: NotificationCompat.Builder =
                NotificationCompat.Builder(MyApp.context, CHANNEL_ID)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("报告")
                    .setContentText("报告") //以下为关键的2行
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setCategory(NotificationCompat.CATEGORY_CALL)
            val notifyManager =
                context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
            notifyManager.notify(0, builder.build())

            context?.startActivity(intent)
        } catch (throwable: Throwable) {
        }

    }

    override fun onMultiActionClicked(p0: Context?, p1: Intent?) {
        super.onMultiActionClicked(p0, p1)

    }

    override fun onNotificationSettingsCheck(p0: Context?, p1: Boolean, p2: Int) {
        super.onNotificationSettingsCheck(p0, p1, p2)

    }
}

2.修改MyService的清单文件配置

需要填入自己的包名(xxxx.xxx.xxx)
<receiver
            android:name="xxx.xxx.xxx.service.MyService"
            android:enabled="true"
            android:exported="false" >
            <intent-filter>
                <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
                <action android:name="cn.jpush.android.intent.REGISTRATION" />
                <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
                <action android:name="cn.jpush.android.intent.NOTIFICATION_CLICK_ACTION" />
                <action android:name="cn.jpush.android.intent.CONNECTION" />
                <category android:name="xxx.xxx.xxx" />
            </intent-filter>
        </receiver>

3.发送和接收后台推送过来的数据

//可以参考上边第一个代码块
val intent = Intent(context, NotificationReportDetailsActivity::class.java)
val bundle = Bundle()
//notificationExtras存放的后台发送过来的数据,json串格式
bundle.putString(JPushInterface.EXTRA_ALERT, message?.notificationExtras)
intent.putExtras(bundle)
context?.startActivity(intent)

val notificationExtras = 
intent.getStringExtra(JPushInterface.EXTRA_ALERT)
//因为后台发送过的数据是json串的格式,所以这里需要解析json串,取到自己想要的数据
val jsonObject = JSONObject(notificationExtras)
name = jsonObject.get("name").toString()
LogUtil.e(name)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在uni-app中,我们可以通过以下步骤实现极光推送点击通知跳转到某个页面。 第一步是引入极光推送插件,可以通过uni-app官方插件市场或者手动下载插件并导入项目中。 第二步是在App.vue文件中配置极光推送相关信息,包括appKey和masterSecret等。具体配置信息可以在极光推送的开发者后台获取。 第三步是在App.vue文件中监听极光推送点击事件,当用户点击通知时触发相应的回调函数。 第四步是在回调函数中处理点击通知的逻辑,包括获取通知的内容和参数,根据参数决定跳转到哪个页面。 具体示例代码如下所示: ``` // 在App.vue文件中监听极光推送点击事件 onShow: function() { // 监听点击通知事件 uni.$on('jpush.click', this.onJpushClick); }, // 处理点击通知的逻辑 onJpushClick: function(payload) { // 获取通知的内容和参数 var content = payload.content; var params = payload.extras; // 根据参数决定跳转到哪个页面 if (params.page === 'home') { uni.navigateTo({ url: '/pages/home/home' }); } else if (params.page === 'about') { uni.navigateTo({ url: '/pages/about/about' }); } else { // 默认跳转到首页 uni.navigateTo({ url: '/pages/home/home' }); } }, ``` 以上就是通过uni-app实现极光推送点击通知跳转到某个页面的步骤和示例代码。通过监听点击事件,我们可以在回调函数中处理逻辑,根据通知的参数跳转到相应的页面

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值