RemoteInputIntentHelper


@RequiresApi(value = 24)
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 companion functions

Intent

Create an intent with action for remote input.

CharSequence?

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

CharSequence?

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

CharSequence?

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

List<RemoteInput>?

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

List<CharSequence>?

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

CharSequence?

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

Boolean

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

Boolean

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

Intent

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

Intent

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

Intent

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

Intent
putRemoteInputsExtra(intent: Intent, remoteInputs: List<RemoteInput>)

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

Intent
putSmartReplyContextExtra(
    intent: Intent,
    smartReplyContext: List<CharSequence>
)

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

Intent
putTitleExtra(intent: Intent, title: CharSequence)

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 companion functions

createActionRemoteInputIntent

Added in 1.1.0
fun createActionRemoteInputIntent(): Intent

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
Intent

The created intent with action for remote input.

getCancelLabelExtra

Added in 1.1.0
fun getCancelLabelExtra(intent: Intent): CharSequence?

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

Parameters
intent: Intent

The intent with given data.

Returns
CharSequence?

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

getConfirmLabelExtra

Added in 1.1.0
fun getConfirmLabelExtra(intent: Intent): CharSequence?

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

Parameters
intent: Intent

The intent with given data.

Returns
CharSequence?

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

getInProgressLabelExtra

Added in 1.1.0
fun getInProgressLabelExtra(intent: Intent): CharSequence?

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

Parameters
intent: Intent

The intent with given data.

Returns
CharSequence?

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

getRemoteInputsExtra

Added in 1.1.0
fun getRemoteInputsExtra(intent: Intent): List<RemoteInput>?

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
intent: Intent

The intent with given data.

Returns
List<RemoteInput>?

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

getSmartReplyContextExtra

Added in 1.1.0
fun getSmartReplyContextExtra(intent: Intent): List<CharSequence>?

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

Parameters
intent: Intent

The intent with given data.

Returns
List<CharSequence>?

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

getTitleExtra

Added in 1.1.0
fun getTitleExtra(intent: Intent): CharSequence?

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

Parameters
intent: Intent

The intent with given data.

Returns
CharSequence?

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

hasRemoteInputsExtra

Added in 1.1.0
fun hasRemoteInputsExtra(intent: Intent): Boolean

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

isActionRemoteInput

Added in 1.1.0
fun isActionRemoteInput(intent: Intent): Boolean

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

putCancelLabelExtra

Added in 1.1.0
fun putCancelLabelExtra(intent: Intent, label: CharSequence): Intent

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
intent: Intent

The intent with given data.

label: CharSequence

The CharSequence to be added.

Returns
Intent

The given intent.

putConfirmLabelExtra

Added in 1.1.0
fun putConfirmLabelExtra(intent: Intent, label: CharSequence): Intent

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
intent: Intent

The intent with given data.

label: CharSequence

The CharSequence to be added.

Returns
Intent

The given intent.

putInProgressLabelExtra

Added in 1.1.0
fun putInProgressLabelExtra(intent: Intent, label: CharSequence): Intent

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
intent: Intent

The intent with given data.

label: CharSequence

The CharSequence to be added.

Returns
Intent

The given intent.

putRemoteInputsExtra

Added in 1.1.0
fun putRemoteInputsExtra(intent: Intent, remoteInputs: List<RemoteInput>): Intent

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
intent: Intent

The intent with given data.

remoteInputs: List<RemoteInput>

The array of RemoteInput to be added.

putSmartReplyContextExtra

fun putSmartReplyContextExtra(
    intent: Intent,
    smartReplyContext: List<CharSequence>
): Intent

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
intent: Intent

The intent with given data.

smartReplyContext: List<CharSequence>

The string to be added.

Returns
Intent

The given intent.

putTitleExtra

Added in 1.1.0
fun putTitleExtra(intent: Intent, title: CharSequence): 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".

Parameters
intent: Intent

The intent with given data.

title: CharSequence

The CharSequence to be added.

Returns
Intent

The given intent.