14

There's a new function called setAllowDataType on RemoteInput.Builder in API 26. What is this used for? I tried the following:

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()

Which should set isDataOnly to true on the RemoteInput, but the notification appeared as the following on the phone. Clicking on the Image button does nothing. What is this for? I can't find any documentation, release notes, or tutorials on this function.


Update

It looks like the data only types are missing from the notification when it is actually posted. Looking through the builder code, when adding Actions to the notification, it uses level 24 which strips out the data types entirely: https://android.googlesource.com/platform/frameworks/support/+/oreo-release/compat/api26/android/support/v4/app/NotificationCompatApi26.java#108

Original question still stands.

Jason
  • 13,563
  • 15
  • 74
  • 125
  • 1
    What's interesting, is that in `NotificationCompatApi21` `null` is being returned when `allowedDataTypes` should be. See implementation [here](https://android.googlesource.com/platform/frameworks/support/+/oreo-release/compat/api21/android/support/v4/app/NotificationCompatApi21.java#273). – azizbekian Dec 11 '17 at 06:53
  • Looks like a way to paste or drop something to `RemoteInput`... – Miha_x64 Dec 11 '17 at 07:47
  • 1
    I can't see where that is used in the Android 8.0 source code, other than self-referential stuff (e.g., tests confirming that `setAllowDataType()` populates the `RemoteInput` properly). It looks like `addDataResultToIntent()` is the counterpart, providing `Uri` values to be delivered as part of the result... but I can't find where *that* is used other in similarly self-referential stuff. Perhaps this is a partial implementation that leaked into the Android 8.0 SDK by accident and will get fleshed out in the next major Android update. – CommonsWare Dec 12 '17 at 23:35
  • Chiming in here 2 years later... Still no idea what the data types are; only seem to be able to get string text via user input or choices to work. – Elliot Hesp Dec 11 '19 at 09:52
  • I think Android 12 now enables image replies from the notification. – Panther Dec 01 '21 at 12:27
  • That's what they write: "In Android 12, you can now enrich your app’s notification experience by providing animated images in MessagingStyle() and BigPictureStyle() notifications. Also, your app can now enable users to send image messages when they reply to messages from the notification shade." – Panther Dec 01 '21 at 12:27

2 Answers2

0

From the docs it says the following:

Specifies whether the user can provide arbitrary values. This allows an input to accept non-textual values. Examples of usage are an input that wants audio or an image.

So, I believe if I'm reading this correctly, that the function setAllowDataType is to add allowable types to the input field. So if a user wanted to add gifs, imgs, etc... they could. By default, I do not believe the user can add these kinds of items.

user3331142
  • 1,222
  • 1
  • 11
  • 22
0

On Android 12 you can now use .setAllowDataType("image/*", true) with RemoteInput to accept image replies through the notification reply feature.

There is no button to select an image, but many keyboards offer features to paste stickers or gifs directly into the notification.

Panther
  • 435
  • 4
  • 16