RemoteInput


public final class RemoteInput
extends Object implements Parcelable

java.lang.Object
   ↳ android.app.RemoteInput


A RemoteInput object specifies input to be collected from a user to be passed along with an intent inside a PendingIntent that is sent. Always use RemoteInput.Builder to create instances of this class.

See Replying to notifications for more information on how to use this class.

The following example adds a RemoteInput to a Notification.Action, sets the result key as quick_reply, and sets the label as Quick reply. Users are prompted to input a response when they trigger the action. The results are sent along with the intent and can be retrieved with the result key (provided to the Builder constructor) from the Bundle returned by getResultsFromIntent(Intent).

 public static final String KEY_QUICK_REPLY_TEXT = "quick_reply";
 Notification.Action action = new Notification.Action.Builder(
         R.drawable.reply, "Reply", actionIntent)
         .addRemoteInput(new RemoteInput.Builder(KEY_QUICK_REPLY_TEXT)
                 .setLabel("Quick reply").build())
         .build();

When the PendingIntent is fired, the intent inside will contain the input results if collected. To access these results, use the getResultsFromIntent(Intent) function. The result values will present under the result key passed to the Builder constructor.

 public static final String KEY_QUICK_REPLY_TEXT = "quick_reply";
 Bundle results = RemoteInput.getResultsFromIntent(intent);
 if (results != null) {
     CharSequence quickReplyResult = results.getCharSequence(KEY_QUICK_REPLY_TEXT);
 }

Summary

Nested classes

class RemoteInput.Builder

Builder class for RemoteInput objects. 

Constants

int EDIT_CHOICES_BEFORE_SENDING_AUTO

The platform will determine whether choices will be edited before being sent to the app.

int EDIT_CHOICES_BEFORE_SENDING_DISABLED

Tapping on a choice should send the input immediately, without letting the user edit it.

int EDIT_CHOICES_BEFORE_SENDING_ENABLED

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

String EXTRA_RESULTS_DATA

Extra added to a clip data intent object to hold the text results bundle.

String RESULTS_CLIP_LABEL

Label used to denote the clip data type used for remote input transport

int SOURCE_CHOICE

The user selected one of the choices from getChoices().

int SOURCE_FREE_FORM_INPUT

The user manually entered the data.

Inherited constants

Fields

public static final Creator<RemoteInput> CREATOR

Public methods

static void addDataResultToIntent(RemoteInput remoteInput, Intent intent, Map<StringUri> results)

Same as addResultsToIntent(RemoteInput, Intent, Bundle) but for setting data results.

static void addResultsToIntent(RemoteInput[] remoteInputs, Intent intent, Bundle results)

Populate an intent object with the text results gathered from remote input.

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

boolean getAllowFreeFormInput()

Get whether or not users can provide an arbitrary value for input.

Set<String> getAllowedDataTypes()

Get possible non-textual inputs that are accepted.

CharSequence[] getChoices()

Get possible input choices.

static Map<StringUri> getDataResultsFromIntent(Intent intent, String remoteInputResultKey)

Similar as getResultsFromIntent(Intent) but retrieves data results for a specific RemoteInput result.

int getEditChoicesBeforeSending()

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

Bundle getExtras()

Get additional metadata carried around with this remote input.

CharSequence getLabel()

Get the label to display to users when collecting this input.

String getResultKey()

Get the key that the result of this input will be set in from the Bundle returned by getResultsFromIntent(Intent) when the PendingIntent is sent.

static Bundle getResultsFromIntent(Intent intent)

Get the remote input text results bundle from an intent.

static int getResultsSource(Intent intent)

Get the source of the RemoteInput results.

boolean isDataOnly()

Returns true if the input only accepts data, meaning getAllowFreeFormInput() is false, getChoices() is null or empty, and getAllowedDataTypes() is non-null and not empty.

static void setResultsSource(Intent intent, int source)

Set the source of the RemoteInput results.

void writeToParcel(Parcel out, int flags)

Flatten this object in to a Parcel.

Inherited methods

Constants

EDIT_CHOICES_BEFORE_SENDING_AUTO

Added in API level 29
public static final int EDIT_CHOICES_BEFORE_SENDING_AUTO

The platform will determine whether choices will be edited before being sent to the app.

Constant Value: 0 (0x00000000)

EDIT_CHOICES_BEFORE_SENDING_DISABLED

Added in API level 29
public static final int EDIT_CHOICES_BEFORE_SENDING_DISABLED

Tapping on a choice should send the input immediately, without letting the user edit it.

Constant Value: 1 (0x00000001)

EDIT_CHOICES_BEFORE_SENDING_ENABLED

Added in API level 29
public static final int EDIT_CHOICES_BEFORE_SENDING_ENABLED

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

Constant Value: 2 (0x00000002)

EXTRA_RESULTS_DATA

Added in API level 20
public static final String EXTRA_RESULTS_DATA

Extra added to a clip data intent object to hold the text results bundle.

Constant Value: "android.remoteinput.resultsData"

RESULTS_CLIP_LABEL

Added in API level 20
public static final String RESULTS_CLIP_LABEL

Label used to denote the clip data type used for remote input transport

Constant Value: "android.remoteinput.results"

SOURCE_CHOICE

Added in API level 28
public static final int SOURCE_CHOICE

The user selected one of the choices from getChoices().

Constant Value: 1 (0x00000001)

SOURCE_FREE_FORM_INPUT

Added in API level 28
public static final int SOURCE_FREE_FORM_INPUT

The user manually entered the data.

Constant Value: 0 (0x00000000)

Fields

CREATOR

Added in API level 20
public static final Creator<RemoteInput> CREATOR

Public methods

addDataResultToIntent

Added in API level 26
public static void addDataResultToIntent (RemoteInput remoteInput, 
                Intent intent, 
                Map<StringUri> results)

Same as addResultsToIntent(RemoteInput, Intent, Bundle) but for setting data results. This is used for inputs that accept non-textual results (see Builder.setAllowDataType). Only one result can be provided for every mime type accepted by the RemoteInput. If multiple inputs of the same mime type are expected then multiple RemoteInputs should be used.

Parameters
remoteInput RemoteInput: The remote input for which results are being provided

intent Intent: The intent to add remote input results to. The ClipData field of the intent will be modified to contain the results.

results Map: A map of mime type to the Uri result for that mime type.

addResultsToIntent

Added in API level 20
public static void addResultsToIntent (RemoteInput[] remoteInputs, 
                Intent intent, 
                Bundle results)

Populate an intent object with the text results gathered from remote input. This method should only be called by remote input collection services when sending results to a pending intent.

Parameters
remoteInputs RemoteInput: The remote inputs for which results are being provided

intent Intent: The intent to add remote inputs to. The ClipData field of the intent will be modified to contain the results.

results Bundle: A bundle holding the remote input results. This bundle should be populated with keys matching the result keys specified in remoteInputs with values being the CharSequence results per key.

describeContents

Added in API level 20
public int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(android.os.Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or CONTENTS_FILE_DESCRIPTOR

getAllowFreeFormInput

Added in API level 20
public boolean getAllowFreeFormInput ()

Get whether or not users can provide an arbitrary value for input. If you set this to false, users must select one of the choices in getChoices(). An IllegalArgumentException is thrown if you set this to false and getChoices() returns null or empty.

Returns
boolean

getAllowedDataTypes

Added in API level 26
public Set<String> getAllowedDataTypes ()

Get possible non-textual inputs that are accepted. This can be null if the input does not accept non-textual values. See Builder.setAllowDataType.

Returns
Set<String>

getChoices

Added in API level 20
public CharSequence[] getChoices ()

Get possible input choices. This can be null if there are no choices to present.

Returns
CharSequence[]

getDataResultsFromIntent

Added in API level 26
public static Map<StringUri> getDataResultsFromIntent (Intent intent, 
                String remoteInputResultKey)

Similar as getResultsFromIntent(Intent) but retrieves data results for a specific RemoteInput result. To retrieve a value use:

 Map<String, Uri> results =
     RemoteInput.getDataResultsFromIntent(intent, REMOTE_INPUT_KEY);
 if (results != null) {
   Uri data = results.get(MIME_TYPE_OF_INTEREST);
 }
 
 

Parameters
intent Intent: The intent object that fired in response to an action or content intent which also had one or more remote input requested.

remoteInputResultKey String: The result key for the RemoteInput you want results for.

Returns
Map<StringUri>

getEditChoicesBeforeSending

Added in API level 29
public int getEditChoicesBeforeSending ()

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

Returns
int Value is EDIT_CHOICES_BEFORE_SENDING_AUTO, EDIT_CHOICES_BEFORE_SENDING_DISABLED, or EDIT_CHOICES_BEFORE_SENDING_ENABLED

getExtras

Added in API level 20
public Bundle getExtras ()

Get additional metadata carried around with this remote input.

Returns
Bundle

getLabel

Added in API level 20
public CharSequence getLabel ()

Get the label to display to users when collecting this input.

Returns
CharSequence

getResultKey

Added in API level 20
public String getResultKey ()

Get the key that the result of this input will be set in from the Bundle returned by getResultsFromIntent(Intent) when the PendingIntent is sent.

Returns
String

getResultsFromIntent

Added in API level 20
public static Bundle getResultsFromIntent (Intent intent)

Get the remote input text results bundle from an intent. The returned Bundle will contain a key/value for every result key populated with text by remote input collector. Use the Bundle.getCharSequence(String) method to retrieve a value. For non-text results use getDataResultsFromIntent(Intent, String).

Parameters
intent Intent: The intent object that fired in response to an action or content intent which also had one or more remote input requested.

Returns
Bundle

getResultsSource

Added in API level 28
public static int getResultsSource (Intent intent)

Get the source of the RemoteInput results.

Parameters
intent Intent: The intent object that fired in response to an action or content intent which also had one or more remote input requested.

Returns
int The source of the results. If no source was set, SOURCE_FREE_FORM_INPUT will be returned. Value is SOURCE_FREE_FORM_INPUT, or SOURCE_CHOICE

isDataOnly

Added in API level 26
public boolean isDataOnly ()

Returns true if the input only accepts data, meaning getAllowFreeFormInput() is false, getChoices() is null or empty, and getAllowedDataTypes() is non-null and not empty.

Returns
boolean

setResultsSource

Added in API level 28
public static void setResultsSource (Intent intent, 
                int source)

Set the source of the RemoteInput results. This method should only be called by remote input collection services (e.g. NotificationListenerService) when sending results to a pending intent.

Parameters
intent Intent: The intent to add remote input source to. The ClipData field of the intent will be modified to contain the source.

source int: The source of the results. Value is SOURCE_FREE_FORM_INPUT, or SOURCE_CHOICE

writeToParcel

Added in API level 20
public void writeToParcel (Parcel out, 
                int flags)

Flatten this object in to a Parcel.

Parameters
out Parcel: The Parcel in which the object should be written. This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES