Stay organized with collections Save and categorize content based on your preferences.

RemoteInput.Builder

public final class RemoteInput.Builder


Builder class for androidx.core.app.RemoteInput objects.

Summary

Public constructors

Builder(@NonNull String resultKey)

Create a builder object for androidx.core.app.RemoteInput objects.

Public methods

@NonNull RemoteInput.Builder

Merge additional metadata into this builder.

@NonNull RemoteInput

Combine all of the options that have been set and return a new object.

@NonNull Bundle

Get the metadata Bundle used by this Builder.

@NonNull RemoteInput.Builder
setAllowDataType(@NonNull String mimeType, boolean doAllow)

Specifies whether the user can provide arbitrary values.

@NonNull RemoteInput.Builder
setAllowFreeFormInput(boolean allowFreeFormTextInput)

Specifies whether the user can provide arbitrary text values.

@NonNull RemoteInput.Builder
setChoices(@Nullable CharSequence[] choices)

Specifies choices available to the user to satisfy this input.

@NonNull RemoteInput.Builder
setEditChoicesBeforeSending(int editChoicesBeforeSending)

Specifies whether tapping on a choice should let the user edit the input before it is sent to the app.

@NonNull RemoteInput.Builder

Set a label to be displayed to the user when collecting this input.

Public constructors

Builder

public Builder(@NonNull String resultKey)

Create a builder object for androidx.core.app.RemoteInput objects.

Parameters
@NonNull String resultKey

the Bundle key that refers to this input when collected from the user

Public methods

addExtras

public @NonNull RemoteInput.Builder addExtras(@NonNull Bundle extras)

Merge additional metadata into this builder.

Values within the Bundle will replace existing extras values in this Builder.

See also
getExtras

build

public @NonNull RemoteInput build()

Combine all of the options that have been set and return a new object.

getExtras

public @NonNull Bundle getExtras()

Get the metadata Bundle used by this Builder.

The returned Bundle is shared with this Builder.

setAllowDataType

public @NonNull RemoteInput.Builder setAllowDataType(@NonNull String mimeType, boolean doAllow)

Specifies whether the user can provide arbitrary values.

Parameters
@NonNull String mimeType

A mime type that results are allowed to come in. Be aware that text results (see setAllowFreeFormInput are allowed by default. If you do not want text results you will have to pass false to setAllowFreeFormInput

boolean doAllow

Whether the mime type should be allowed or not

Returns
@NonNull RemoteInput.Builder

this object for method chaining

setAllowFreeFormInput

public @NonNull RemoteInput.Builder setAllowFreeFormInput(boolean allowFreeFormTextInput)

Specifies whether the user can provide arbitrary text values.

Parameters
boolean allowFreeFormTextInput

The default is true. If you specify false, you must either provide a non-null and non-empty array to setChoices, or enable a data result in setAllowDataType. Otherwise an IllegalArgumentException is thrown

Returns
@NonNull RemoteInput.Builder

this object for method chaining

setChoices

public @NonNull RemoteInput.Builder setChoices(@Nullable CharSequence[] choices)

Specifies choices available to the user to satisfy this input.

Note: Starting in Android P, these choices will always be shown on phones if the app's target SDK is >= P. However, these choices may also be rendered on other types of devices regardless of target SDK.

Parameters
@Nullable CharSequence[] choices

an array of pre-defined choices for users input. You must provide a non-null and non-empty array if you disabled free form input using setAllowFreeFormInput

Returns
@NonNull RemoteInput.Builder

this object for method chaining

setEditChoicesBeforeSending

public @NonNull RemoteInput.Builder setEditChoicesBeforeSending(int editChoicesBeforeSending)

Specifies whether tapping on a choice should let the user edit the input before it is sent to the app. The default is EDIT_CHOICES_BEFORE_SENDING_AUTO. It cannot be used if setAllowFreeFormInput has been set to false.

setLabel

public @NonNull RemoteInput.Builder setLabel(@Nullable CharSequence label)

Set a label to be displayed to the user when collecting this input.

Parameters
@Nullable CharSequence label

The label to show to users when they input a response

Returns
@NonNull RemoteInput.Builder

this object for method chaining