【发布时间】:2018-05-23 03:50:49
【问题描述】:
在 API 26 中的 RemoteInput.Builder 上有一个名为 setAllowDataType 的新函数。它是用来做什么的?我尝试了以下方法:
val remoteInput = RemoteInput.Builder(KEY_TEXT_REPLY)
.setLabel("Image")
.setAllowFreeFormInput(false)
.setChoices(null)
.setAllowDataType("image/*", true)
.setAllowDataType("image/png", true)
.setAllowDataType("image/jpg", true)
.setAllowDataType("image/gif", true)
.build()
应该在RemoteInput 上将isDataOnly 设置为true,但手机上的通知显示如下。单击Image 按钮不会执行任何操作。这个是来做什么的?我找不到有关此功能的任何文档、发行说明或教程。
更新
在实际发布时,通知中似乎缺少仅数据类型。查看构建器代码,在将Actions 添加到通知时,它使用完全去除数据类型的级别24:https://android.googlesource.com/platform/frameworks/support/+/oreo-release/compat/api26/android/support/v4/app/NotificationCompatApi26.java#108
原来的问题仍然存在。
【问题讨论】:
-
有趣的是,在
NotificationCompatApi21中,null被返回,而allowedDataTypes应该是。参见实现here。 -
看起来像是一种将某些内容粘贴或拖放到
RemoteInput... -
除了自我引用的东西(例如,确认
setAllowDataType()正确填充RemoteInput的测试)之外,我看不到它在Android 8.0 源代码中的使用位置。看起来addDataResultToIntent()是对应的,提供Uri值作为结果的一部分传递......但我找不到 that 在其他类似的自我引用的东西中使用的地方.也许这是一个偶然泄露到 Android 8.0 SDK 中的部分实现,并将在下一次主要的 Android 更新中得到充实。 -
两年后在这里插话......仍然不知道数据类型是什么;似乎只能通过用户输入或选择来获取字符串文本。
-
我认为 Android 12 现在可以从通知中回复图片。
标签: android notifications android-notifications remote-input