首页 > 解决方案 > 如何调试通知中的智能回复?

问题描述

随着 Android 10 的发布,他们在通知中宣布了一项名为智能回复(已存在于 Gmail/Messages 应用程序中)的新功能。

现在,我的应用中有很多关于通知的代码,我们经常使用它们。出于显而易见的原因,我想测试我们当前的实现是否与那些新系统生成的上下文操作一起正常工作。

有谁知道如何使用 Android 10 模拟器在通知中手动触发智能回复?我一直试图让它们出现一整天(通过在我的应用程序中创建一个虚假通知并更改其内容,例如用地址、电话号码等填充内容)但没有成功。

谢谢 !

标签: androidandroid-emulator

解决方案


你的通知有回复动作吗?

val remoteInput = RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT)
                    .setLabel(replyLabel)
                    .setChoices("Yes","No")// hardcoded responses for Android P
                    .build()

如果您有硬编码setChoices(listOfReplies)系统将不会提供智能回复。

//When you build action setAllowGeneratedReplies to true
val replyAction = NotificationCompat.Action.Builder(
                    R.drawable.ic_reply_white_18dp,
                    replyLabel,
                    replyActionPendingIntent)
                    .addRemoteInput(remoteInput)
                    .setAllowGeneratedReplies(true)
                    .build()

// 对于建议的操作,将 setAllowSystemGeneratedContextualActions 设置为 true

               .notificationCompatBuilder.setStyle()
                .setContentTitle(contentTitle)
                .setContentText("Hey lets meet for dinner at xx sretee Rd, New York Postocde")
                .setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(
                        resources,
                        R.drawable.ic_person_black_48dp))

                .setAllowSystemGeneratedContextualActions(true)
                .setSubText(Integer.toString(1))
                .addAction(replyAction)

话虽如此,当前的模拟器不提供任何智能回复,我尚未在运行 10 的实际设备上对其进行测试

还要确保在通知设置中启用了智能回复在此处输入图像描述


推荐阅读