Android APIs
public final class

RemoteInput

extends Object
implements Parcelable
java.lang.Object
   ↳ android.app.RemoteInput

Class Overview

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 Receiving Voice Input from a Notification 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 RemoteInput.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 RemoteInput.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
String EXTRA_RESULTS_DATA Extra added to a clip data intent object to hold the results bundle.
String RESULTS_CLIP_LABEL Label used to denote the clip data type used for remote input transport
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<RemoteInput> CREATOR
Public Methods
static void addResultsToIntent(RemoteInput[] remoteInputs, Intent intent, Bundle results)
Populate an intent object with the results gathered from remote input.
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
boolean getAllowFreeFormInput()
Get whether or not users can provide an arbitrary value for input.
CharSequence[] getChoices()
Get possible input choices.
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 results bundle from an intent.
void writeToParcel(Parcel out, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final String EXTRA_RESULTS_DATA

Added in API level 20

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

Constant Value: "android.remoteinput.resultsData"

public static final String RESULTS_CLIP_LABEL

Added in API level 20

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

Constant Value: "android.remoteinput.results"

Fields

public static final Creator<RemoteInput> CREATOR

Added in API level 20

Public Methods

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

Added in API level 20

Populate an intent object with the 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 The remote inputs for which results are being provided
intent The intent to add remote inputs to. The ClipData field of the intent will be modified to contain the results.
results 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 result per key.

public int describeContents ()

Added in API level 20

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

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public boolean getAllowFreeFormInput ()

Added in API level 20

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.

public CharSequence[] getChoices ()

Added in API level 20

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

public Bundle getExtras ()

Added in API level 20

Get additional metadata carried around with this remote input.

public CharSequence getLabel ()

Added in API level 20

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

public String getResultKey ()

Added in API level 20

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.

public static Bundle getResultsFromIntent (Intent intent)

Added in API level 20

Get the remote input results bundle from an intent. The returned Bundle will contain a key/value for every result key populated by remote input collector. Use the getCharSequence(String) method to retrieve a value.

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

public void writeToParcel (Parcel out, int flags)

Added in API level 20

Flatten this object in to a Parcel.

Parameters
out The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.