RemoteInputIntentHelper
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? |
getCancelLabelExtra(intent: Intent)Returns the |
CharSequence? |
getConfirmLabelExtra(intent: Intent)Returns the |
CharSequence? |
getInProgressLabelExtra(intent: Intent)Returns the |
List<RemoteInput>? |
getRemoteInputsExtra(intent: Intent)Returns the array of |
List<CharSequence>? |
getSmartReplyContextExtra(intent: Intent)Returns the array of |
CharSequence? |
getTitleExtra(intent: Intent)Returns the |
Boolean |
hasRemoteInputsExtra(intent: Intent)Checks whether the given |
Boolean |
isActionRemoteInput(intent: Intent)Checks whether the action of the given intent is for remote input. |
Intent |
putCancelLabelExtra(intent: Intent, label: CharSequence)Adds the |
Intent |
putConfirmLabelExtra(intent: Intent, label: CharSequence)Adds the |
Intent |
putInProgressLabelExtra(intent: Intent, label: CharSequence)Adds the |
Intent |
putRemoteInputsExtra(intent: Intent, remoteInputs: List<RemoteInput>)Adds the array of |
Intent |
putSmartReplyContextExtra(Adds the array of |
Intent |
putTitleExtra(intent: Intent, title: CharSequence)Adds the |
Public companion functions
createActionRemoteInputIntent
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
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 |
getConfirmLabelExtra
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 |
getInProgressLabelExtra
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 |
getRemoteInputsExtra
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 |
getSmartReplyContextExtra
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 |
getTitleExtra
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 |
hasRemoteInputsExtra
fun hasRemoteInputsExtra(intent: Intent): Boolean
Checks whether the given Intent has extra for the array of RemoteInput.
isActionRemoteInput
fun isActionRemoteInput(intent: Intent): Boolean
Checks whether the action of the given intent is for remote input.
putCancelLabelExtra
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
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
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
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 |
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
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. |