What are AllowedDataTypes on RemoteInput?

642 views Asked by At

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.

2

There are 2 answers

0
Panther On

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.

0
user3331142 On

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.