RemoteInputIntentHelper
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 |
getCancelLabelExtra(@NonNull Intent intent)Returns the |
static final @Nullable CharSequence |
getConfirmLabelExtra(@NonNull Intent intent)Returns the |
static final @Nullable CharSequence |
getInProgressLabelExtra(@NonNull Intent intent)Returns the |
static final @Nullable List<@NonNull RemoteInput> |
getRemoteInputsExtra(@NonNull Intent intent)Returns the array of |
static final @Nullable List<@NonNull CharSequence> |
getSmartReplyContextExtra(@NonNull Intent intent)Returns the array of |
static final @Nullable CharSequence |
getTitleExtra(@NonNull Intent intent)Returns the |
static final boolean |
hasRemoteInputsExtra(@NonNull Intent intent)Checks whether the given |
static final boolean |
isActionRemoteInput(@NonNull Intent intent)Checks whether the action of the given intent is for remote input. |
static final @NonNull Intent |
putCancelLabelExtra(@NonNull Intent intent, @NonNull CharSequence label)Adds the |
static final @NonNull Intent |
putConfirmLabelExtra(@NonNull Intent intent, @NonNull CharSequence label)Adds the |
static final @NonNull Intent |
putInProgressLabelExtra(Adds the |
static final @NonNull Intent |
putRemoteInputsExtra(Adds the array of |
static final @NonNull Intent |
putSmartReplyContextExtra(Adds the array of |
static final @NonNull Intent |
putTitleExtra(@NonNull Intent intent, @NonNull CharSequence title)Adds the |
Public methods
createActionRemoteInputIntent
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.
getCancelLabelExtra
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.
| Returns | |
|---|---|
@Nullable CharSequence |
The CharSequence previously added with |
getConfirmLabelExtra
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.
| Returns | |
|---|---|
@Nullable CharSequence |
The CharSequence previously added with |
getInProgressLabelExtra
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.
| Returns | |
|---|---|
@Nullable CharSequence |
The CharSequence previously added with |
getRemoteInputsExtra
public static final @Nullable List<@NonNull RemoteInput> getRemoteInputsExtra(@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.
| Returns | |
|---|---|
@Nullable List<@NonNull RemoteInput> |
The array of |
getSmartReplyContextExtra
public static final @Nullable List<@NonNull CharSequence> getSmartReplyContextExtra(@NonNull Intent intent)
Returns the array of CharSequence from the given Intent that provides context for creating Smart Reply choices within a RemoteInput session.
| Returns | |
|---|---|
@Nullable List<@NonNull CharSequence> |
The array of |
getTitleExtra
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.
| Returns | |
|---|---|
@Nullable CharSequence |
The CharSequence previously added with |
hasRemoteInputsExtra
public static final boolean hasRemoteInputsExtra(@NonNull Intent intent)
Checks whether the given Intent has extra for the array of RemoteInput.
isActionRemoteInput
public static final boolean isActionRemoteInput(@NonNull Intent intent)
Checks whether the action of the given intent is for remote input.
putCancelLabelExtra
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. |
putConfirmLabelExtra
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. |
putInProgressLabelExtra
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. |
putRemoteInputsExtra
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 |
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.
putTitleExtra
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. |