RemoteInputIntentHelper

@RequiresApi(value = 24)
public final class RemoteInputIntentHelper


Helper functions for supporting remote inputs through starting an android.content.Intent.

The following example prompts the user to provide input for one RemoteInput by starting an input activity.

public const val KEY_QUICK_REPLY_TEXT: String = "quick_reply";
val remoteInputs: List<RemoteInput> = listOf(
new RemoteInput.Builder(KEY_QUICK_REPLY_TEXT).setLabel("Quick reply").build()
);
val intent: Intent = createActionRemoteInputIntent();
putRemoteInputsExtra(intent, remoteInputs)
startActivityForResult(intent);

The intent returned via android.app.Activity.onActivityResult will contain the input results if collected, for example:

override fun onActivityResult(requestCode: Int, resultCode: Int, intentResults: Intent?) {
val results: Bundle = RemoteInput.getResultsFromIntent(intentResults)
val quickReplyResult: CharSequence? = results.getCharSequence(KEY_QUICK_REPLY_TEXT)
}

More information about accessing these results can be found in RemoteInput.

Summary

Public methods

static final @NonNull Intent

Create an intent with action for remote input.

static final @Nullable CharSequence

Returns the CharSequence from the given Intent that specifies what is displayed to cancel the action.

static final @Nullable CharSequence

Returns the CharSequence from the given Intent that specifies what is displayed to confirm that the action should be executed.

static final @Nullable CharSequence

Returns the CharSequence from the given Intent that specifies what is displayed while the wearable is preparing to automatically execute the action.

static final @Nullable List<@NonNull RemoteInput>

Returns the array of RemoteInput from the given Intent that specifies inputs to be collected from a user.

static final @Nullable List<@NonNull CharSequence>

Returns the array of CharSequence from the given Intent that provides context for creating Smart Reply choices within a RemoteInput session.

static final @Nullable CharSequence

Returns the CharSequence from the given Intent that specifies what is displayed on top of the confirmation screen to describe the action.

static final boolean

Checks whether the given Intent has extra for the array of RemoteInput.

static final boolean

Checks whether the action of the given intent is for remote input.

static final @NonNull Intent

Adds the CharSequence to the given Intent that specifies what is displayed to cancel the action.

static final @NonNull Intent

Adds the CharSequence to the given Intent that specifies what is displayed to confirm that the action should be executed.

static final @NonNull Intent
putInProgressLabelExtra(
    @NonNull Intent intent,
    @NonNull CharSequence label
)

Adds the CharSequence to the given Intent that specifies what is displayed while the wearable is preparing to automatically execute the action.

static final @NonNull Intent
putRemoteInputsExtra(
    @NonNull Intent intent,
    @NonNull List<@NonNull RemoteInput> remoteInputs
)

Adds the array of RemoteInput to the given Intent that specifies inputs collected from a user.

static final @NonNull Intent
putSmartReplyContextExtra(
    @NonNull Intent intent,
    @NonNull List<@NonNull CharSequence> smartReplyContext
)

Adds the array of CharSequence to the given Intent that provides context for creating Smart Reply choices within a RemoteInput session.

static final @NonNull Intent

Adds the CharSequence to the given Intent that specifies what is displayed on top of the confirmation screen to describe the action like "SMS" or "Email".

Public methods

createActionRemoteInputIntent

Added in 1.1.0
public static final @NonNull Intent createActionRemoteInputIntent()

Create an intent with action for remote input. This intent can be used to start an activity that will prompt the user for input. With the other helpers in this class to specify the intent extras, we can configure the behaviour of the input activity, such as specifying input be collected from a user by populating with an array of RemoteInput with putRemoteInputsExtra.

Returns
@NonNull Intent

The created intent with action for remote input.

getCancelLabelExtra

Added in 1.1.0
public static final @Nullable CharSequence getCancelLabelExtra(@NonNull Intent intent)

Returns the CharSequence from the given Intent that specifies what is displayed to cancel the action.

Parameters
@NonNull Intent intent

The intent with given data.

Returns
@Nullable CharSequence

The CharSequence previously added with putCancelLabelExtra or null if no value is found.

getConfirmLabelExtra

Added in 1.1.0
public static final @Nullable CharSequence getConfirmLabelExtra(@NonNull Intent intent)

Returns the CharSequence from the given Intent that specifies what is displayed to confirm that the action should be executed.

Parameters
@NonNull Intent intent

The intent with given data.

Returns
@Nullable CharSequence

The CharSequence previously added with putConfirmLabelExtra or null if no value is found.

getInProgressLabelExtra

Added in 1.1.0
public static final @Nullable CharSequence getInProgressLabelExtra(@NonNull Intent intent)

Returns the CharSequence from the given Intent that specifies what is displayed while the wearable is preparing to automatically execute the action.

Parameters
@NonNull Intent intent

The intent with given data.

Returns
@Nullable CharSequence

The CharSequence previously added with putInProgressLabelExtra or null if no value is found.

getRemoteInputsExtra

Added in 1.1.0
public static final @Nullable List<@NonNull RemoteInputgetRemoteInputsExtra(@NonNull Intent intent)

Returns the array of RemoteInput from the given Intent that specifies inputs to be collected from a user. Should be used with Intent created with .createActionRemoteInputIntent.

Parameters
@NonNull Intent intent

The intent with given data.

Returns
@Nullable List<@NonNull RemoteInput>

The array of RemoteInput previously added with putRemoteInputsExtra or null which means no user input required.

getSmartReplyContextExtra

Added in 1.1.0
public static final @Nullable List<@NonNull CharSequencegetSmartReplyContextExtra(@NonNull Intent intent)

Returns the array of CharSequence from the given Intent that provides context for creating Smart Reply choices within a RemoteInput session.

Parameters
@NonNull Intent intent

The intent with given data.

Returns
@Nullable List<@NonNull CharSequence>

The array of CharSequence previously added with putSmartReplyContextExtra or putSmartReplyContextExtra or null if no value is found.

getTitleExtra

Added in 1.1.0
public static final @Nullable CharSequence getTitleExtra(@NonNull Intent intent)

Returns the CharSequence from the given Intent that specifies what is displayed on top of the confirmation screen to describe the action.

Parameters
@NonNull Intent intent

The intent with given data.

Returns
@Nullable CharSequence

The CharSequence previously added with putTitleExtra or null if no value is found.

hasRemoteInputsExtra

Added in 1.1.0
public static final boolean hasRemoteInputsExtra(@NonNull Intent intent)

Checks whether the given Intent has extra for the array of RemoteInput.

isActionRemoteInput

Added in 1.1.0
public static final boolean isActionRemoteInput(@NonNull Intent intent)

Checks whether the action of the given intent is for remote input.

putCancelLabelExtra

Added in 1.1.0
public static final @NonNull Intent putCancelLabelExtra(@NonNull Intent intent, @NonNull CharSequence label)

Adds the CharSequence to the given Intent that specifies what is displayed to cancel the action. This is usually an imperative verb, like "Cancel". Defaults to Cancel.

Parameters
@NonNull Intent intent

The intent with given data.

@NonNull CharSequence label

The CharSequence to be added.

Returns
@NonNull Intent

The given intent.

putConfirmLabelExtra

Added in 1.1.0
public static final @NonNull Intent putConfirmLabelExtra(@NonNull Intent intent, @NonNull CharSequence label)

Adds the CharSequence to the given Intent that specifies what is displayed to confirm that the action should be executed. This is usually an imperative verb like "Send". Defaults to "Send".

Parameters
@NonNull Intent intent

The intent with given data.

@NonNull CharSequence label

The CharSequence to be added.

Returns
@NonNull Intent

The given intent.

putInProgressLabelExtra

Added in 1.1.0
public static final @NonNull Intent putInProgressLabelExtra(
    @NonNull Intent intent,
    @NonNull CharSequence label
)

Adds the CharSequence to the given Intent that specifies what is displayed while the wearable is preparing to automatically execute the action. This is usually a 'ing' verb ending in ellipsis like "Sending...". Defaults to "Sending...".

Parameters
@NonNull Intent intent

The intent with given data.

@NonNull CharSequence label

The CharSequence to be added.

Returns
@NonNull Intent

The given intent.

putRemoteInputsExtra

Added in 1.1.0
public static final @NonNull Intent putRemoteInputsExtra(
    @NonNull Intent intent,
    @NonNull List<@NonNull RemoteInput> remoteInputs
)

Adds the array of RemoteInput to the given Intent that specifies inputs collected from a user. Should be used with Intent created with createActionRemoteInputIntent.

Parameters
@NonNull Intent intent

The intent with given data.

@NonNull List<@NonNull RemoteInput> remoteInputs

The array of RemoteInput to be added.

putSmartReplyContextExtra

public static final @NonNull Intent putSmartReplyContextExtra(
    @NonNull Intent intent,
    @NonNull List<@NonNull CharSequence> smartReplyContext
)

Adds the array of CharSequence to the given Intent that provides context for creating Smart Reply choices within a RemoteInput session. The context should be incoming chat messages that a user will reply to using RemoteInput. Only incoming messages (messages from other users) should be passed via this extra.

The messages should be in the order that they were received with the newest messages at the highest index of the CharSequence[]. For example, a possible value for this extra would be: "hey", "where are you?". In this case, "where are you?" was the most recently received message.

Passing a chat context into RemoteInput using this method does not guarantee that Smart Reply choices will be shown to a user.

Parameters
@NonNull Intent intent

The intent with given data.

@NonNull List<@NonNull CharSequence> smartReplyContext

The string to be added.

Returns
@NonNull Intent

The given intent.

putTitleExtra

Added in 1.1.0
public static final @NonNull Intent putTitleExtra(@NonNull Intent intent, @NonNull CharSequence title)

Adds the CharSequence to the given Intent that specifies what is displayed on top of the confirmation screen to describe the action like "SMS" or "Email".

Parameters
@NonNull Intent intent

The intent with given data.

@NonNull CharSequence title

The CharSequence to be added.

Returns
@NonNull Intent

The given intent.