FileDocCategorySizeDatePackage
RemoteInput.javaAPI DocAndroid 5.1 API11833Thu Mar 12 22:22:10 GMT 2015android.app

RemoteInput

public final class RemoteInput extends Object implements android.os.Parcelable
A {@code RemoteInput} object specifies input to be collected from a user to be passed along with an intent inside a {@link android.app.PendingIntent} that is sent. Always use {@link 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 {@code RemoteInput} to a {@link Notification.Action}, sets the result key as {@code quick_reply}, and sets the label as {@code 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 {@link Builder} constructor) from the Bundle returned by {@link #getResultsFromIntent}.

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 {@link android.app.PendingIntent} is fired, the intent inside will contain the input results if collected. To access these results, use the {@link #getResultsFromIntent} function. The result values will present under the result key passed to the {@link 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);
}

Fields Summary
public static final String
RESULTS_CLIP_LABEL
Label used to denote the clip data type used for remote input transport
public static final String
EXTRA_RESULTS_DATA
Extra added to a clip data intent object to hold the results bundle.
private static final int
FLAG_ALLOW_FREE_FORM_INPUT
private static final int
DEFAULT_FLAGS
private final String
mResultKey
private final CharSequence
mLabel
private final CharSequence[]
mChoices
private final int
mFlags
private final android.os.Bundle
mExtras
public static final Creator
CREATOR
Constructors Summary
private RemoteInput(String resultKey, CharSequence label, CharSequence[] choices, int flags, android.os.Bundle extras)


          
                
        this.mResultKey = resultKey;
        this.mLabel = label;
        this.mChoices = choices;
        this.mFlags = flags;
        this.mExtras = extras;
    
private RemoteInput(android.os.Parcel in)

        mResultKey = in.readString();
        mLabel = in.readCharSequence();
        mChoices = in.readCharSequenceArray();
        mFlags = in.readInt();
        mExtras = in.readBundle();
    
Methods Summary
public static voidaddResultsToIntent(android.app.RemoteInput[] remoteInputs, android.content.Intent intent, android.os.Bundle results)
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.

param
remoteInputs The remote inputs for which results are being provided
param
intent The intent to add remote inputs to. The {@link ClipData} field of the intent will be modified to contain the results.
param
results A bundle holding the remote input results. This bundle should be populated with keys matching the result keys specified in {@code remoteInputs} with values being the result per key.

        Bundle resultsBundle = new Bundle();
        for (RemoteInput remoteInput : remoteInputs) {
            Object result = results.get(remoteInput.getResultKey());
            if (result instanceof CharSequence) {
                resultsBundle.putCharSequence(remoteInput.getResultKey(), (CharSequence) result);
            }
        }
        Intent clipIntent = new Intent();
        clipIntent.putExtra(EXTRA_RESULTS_DATA, resultsBundle);
        intent.setClipData(ClipData.newIntent(RESULTS_CLIP_LABEL, clipIntent));
    
public intdescribeContents()

        return 0;
    
public booleangetAllowFreeFormInput()
Get whether or not users can provide an arbitrary value for input. If you set this to {@code false}, users must select one of the choices in {@link #getChoices}. An {@link IllegalArgumentException} is thrown if you set this to false and {@link #getChoices} returns {@code null} or empty.

        return (mFlags & FLAG_ALLOW_FREE_FORM_INPUT) != 0;
    
public java.lang.CharSequence[]getChoices()
Get possible input choices. This can be {@code null} if there are no choices to present.

        return mChoices;
    
public android.os.BundlegetExtras()
Get additional metadata carried around with this remote input.

        return mExtras;
    
public java.lang.CharSequencegetLabel()
Get the label to display to users when collecting this input.

        return mLabel;
    
public java.lang.StringgetResultKey()
Get the key that the result of this input will be set in from the Bundle returned by {@link #getResultsFromIntent} when the {@link android.app.PendingIntent} is sent.

        return mResultKey;
    
public static android.os.BundlegetResultsFromIntent(android.content.Intent intent)
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 {@link Bundle#getCharSequence(String)} method to retrieve a value.

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

        ClipData clipData = intent.getClipData();
        if (clipData == null) {
            return null;
        }
        ClipDescription clipDescription = clipData.getDescription();
        if (!clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
            return null;
        }
        if (clipDescription.getLabel().equals(RESULTS_CLIP_LABEL)) {
            return clipData.getItemAt(0).getIntent().getExtras().getParcelable(EXTRA_RESULTS_DATA);
        }
        return null;
    
public voidwriteToParcel(android.os.Parcel out, int flags)

        out.writeString(mResultKey);
        out.writeCharSequence(mLabel);
        out.writeCharSequenceArray(mChoices);
        out.writeInt(mFlags);
        out.writeBundle(mExtras);