随着 Android 10 的发布,他们宣布了一项名为 Smart Reply 的新功能(已经存在于 Gmail/Messages 应用程序中)在通知中。
现在,我们在我的应用程序中有很多关于通知的代码,而且我们经常使用它们。出于显而易见的原因,我想测试我们当前的实现是否可以与那些新的 system generated contextual actions 一起正常工作。 .
有谁知道如何使用 Android 10 模拟器在通知中手动触发智能回复?我一整天都在尝试让它们出现(通过在我的应用程序中创建一个虚假通知并更改其内容,例如用地址、电话号码等填充内容)但没有成功。
谢谢!
最佳答案
你的通知有回复 Action 吗?
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 的实际设备上测试它
关于android - 如何调试通知中的智能回复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57995618/