【发布时间】:2021-05-20 13:18:35
【问题描述】:
我已经在我的应用中实现了推送通知。但我们希望在通知中添加点赞和回复按钮。
【问题讨论】:
标签: android push-notification notifications android-notifications
我已经在我的应用中实现了推送通知。但我们希望在通知中添加点赞和回复按钮。
【问题讨论】:
标签: android push-notification notifications android-notifications
您可以使用通知构建器中的添加操作方法向通知添加按钮。
例如:
val yesIntent = Intent(this, MyBroadcastReceiver::class.java)
yesIntent.action = "MY.INTENT.FILTER"
val mPendingYesIntent = PendingIntent.getBroadcast(this, Random().nextInt(), yesIntent, PendingIntent.FLAG_UPDATE_CURRENT)
现在您将待处理的意图设置为通知构建器的操作。 (请注意,我已将待处理的意图由广播接收器捕获,您可以根据需要使用服务或其他东西)
您可以按如下方式添加待处理的意图:
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.your_notif_icon)
.setContentTitle("your title")
.setContentText("your text")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.addAction(R.drawable.icon_needed_for_button, "Like", mPendingYesIntent)
对于内联回复,我建议将通知设为远程输入字段
参考文档:https://developer.android.com/training/notify-user/build-notification#reply-action
【讨论】: