【问题标题】:What are AllowedDataTypes on RemoteInput?RemoteInput 上的 AllowedDataType 是什么?
【发布时间】: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


【解决方案1】:

来自docs 的内容如下:

指定用户是否可以提供任意值。这允许 接受非文本值的输入。使用示例是输入 需要音频或图像。

所以,我相信如果我没看错的话,setAllowDataType 函数就是向输入字段添加允许的类型。因此,如果用户想要添加 gif、img 等……他们可以。默认情况下,我不相信用户可以添加这些类型的项目。

【讨论】:

    【解决方案2】:

    在 Android 12 上,您现在可以使用 .setAllowDataType("image/*", true)RemoteInput 通过通知回复功能接受图片回复。

    没有选择图像的按钮,但许多键盘提供将贴纸或 ​​gif 直接粘贴到通知中的功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 2011-03-23
      • 2016-11-18
      • 2015-12-13
      相关资源
      最近更新 更多