RemoteInput
public final class RemoteInput
Helper for using the android.app.RemoteInput.
Summary
Nested types |
|---|
public final class RemoteInput.BuilderBuilder class for |
Constants |
|
|---|---|
static final int |
The platform will determine whether choices will be edited before being sent to the app. |
static final int |
Tapping on a choice should send the input immediately, without letting the user edit it. |
static final int |
Tapping on a choice should let the user edit the input before it is sent to the app. |
static final String |
EXTRA_RESULTS_DATA = "android.remoteinput.resultsData"Extra added to a clip data intent object to hold the text results bundle. |
static final String |
RESULTS_CLIP_LABEL = "android.remoteinput.results"Label used to denote the clip data type used for remote input transport |
static final int |
SOURCE_CHOICE = 1The user selected one of the choices from |
static final int |
The user manually entered the data. |
Public methods |
|
|---|---|
static void |
addDataResultToIntent(Same as |
static void |
addResultsToIntent(Populate an intent object with the results gathered from remote input. |
boolean |
Get whether or not users can provide an arbitrary value for input. |
@Nullable Set<String> |
|
@Nullable CharSequence[] |
Get possible input choices. |
static @Nullable Map<String, Uri> |
getDataResultsFromIntent(Similar as |
int |
Gets whether tapping on a choice should let the user edit the input before it is sent to the app. |
@NonNull Bundle |
Get additional metadata carried around with this remote input. |
@Nullable CharSequence |
getLabel()Get the label to display to users when collecting this input. |
@NonNull String |
Get the key that the result of this input will be set in from the Bundle returned by |
static @Nullable Bundle |
getResultsFromIntent(@NonNull Intent intent)Get the remote input text results bundle from an intent. |
static int |
getResultsSource(@NonNull Intent intent)Get the source of the RemoteInput results. |
boolean |
Returns true if the input only accepts data, meaning |
static void |
setResultsSource(@NonNull Intent intent, int source)Set the source of the RemoteInput results. |
Constants
EDIT_CHOICES_BEFORE_SENDING_AUTO
public static final int EDIT_CHOICES_BEFORE_SENDING_AUTO = 0
The platform will determine whether choices will be edited before being sent to the app.
EDIT_CHOICES_BEFORE_SENDING_DISABLED
public static final int EDIT_CHOICES_BEFORE_SENDING_DISABLED = 1
Tapping on a choice should send the input immediately, without letting the user edit it.
EDIT_CHOICES_BEFORE_SENDING_ENABLED
public static final int EDIT_CHOICES_BEFORE_SENDING_ENABLED = 2
Tapping on a choice should let the user edit the input before it is sent to the app.
EXTRA_RESULTS_DATA
public static final String EXTRA_RESULTS_DATA = "android.remoteinput.resultsData"
Extra added to a clip data intent object to hold the text results bundle.
RESULTS_CLIP_LABEL
public static final String RESULTS_CLIP_LABEL = "android.remoteinput.results"
Label used to denote the clip data type used for remote input transport
SOURCE_CHOICE
public static final int SOURCE_CHOICE = 1
The user selected one of the choices from getChoices.
SOURCE_FREE_FORM_INPUT
public static final int SOURCE_FREE_FORM_INPUT = 0
The user manually entered the data.
Public methods
addDataResultToIntent
public static void addDataResultToIntent(
@NonNull RemoteInput remoteInput,
@NonNull Intent intent,
@NonNull Map<String, Uri> results
)
Same as addResultsToIntent but for setting data results.
| Parameters | |
|---|---|
@NonNull RemoteInput remoteInput |
The remote input for which results are being provided |
@NonNull Intent intent |
The intent to add remote input results to. The |
@NonNull Map<String, Uri> results |
A map of mime type to the Uri result for that mime type. |
addResultsToIntent
public static void addResultsToIntent(
@NonNull RemoteInput[] remoteInputs,
@NonNull Intent intent,
@NonNull 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.
| Parameters | |
|---|---|
@NonNull RemoteInput[] remoteInputs |
The remote inputs for which results are being provided |
@NonNull Intent intent |
The intent to add remote inputs to. The |
@NonNull Bundle results |
A bundle holding the remote input results. This bundle should be populated with keys matching the result keys specified in |
getAllowFreeFormInput
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.
getChoices
public @Nullable CharSequence[] getChoices()
Get possible input choices. This can be null if there are no choices to present.
getDataResultsFromIntent
public static @Nullable Map<String, Uri> getDataResultsFromIntent(
@NonNull Intent intent,
@NonNull String remoteInputResultKey
)
Similar as getResultsFromIntent 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);
}getEditChoicesBeforeSending
public int getEditChoicesBeforeSending()
Gets whether tapping on a choice should let the user edit the input before it is sent to the app.
getExtras
public @NonNull Bundle getExtras()
Get additional metadata carried around with this remote input.
getLabel
public @Nullable CharSequence getLabel()
Get the label to display to users when collecting this input.
getResultKey
public @NonNull String getResultKey()
Get the key that the result of this input will be set in from the Bundle returned by getResultsFromIntent when the android.app.PendingIntent is sent.
getResultsFromIntent
public static @Nullable Bundle getResultsFromIntent(@NonNull 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 by remote input collector. Use the getCharSequence method to retrieve a value. For data results use getDataResultsFromIntent.
getResultsSource
public static int getResultsSource(@NonNull Intent intent)
Get the source of the RemoteInput results.
| Parameters | |
|---|---|
@NonNull 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, |
| See also | |
|---|---|
SOURCE_FREE_FORM_INPUT |
|
SOURCE_CHOICE |
isDataOnly
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.
setResultsSource
public static void setResultsSource(@NonNull Intent intent, int source)
Set the source of the RemoteInput results. This method should only be called by remote input collection services (e.g. android.service.notification.NotificationListenerService) when sending results to a pending intent.
| Parameters | |
|---|---|
@NonNull Intent intent |
The intent to add remote input source to. The |
int source |
The source of the results. |
| See also | |
|---|---|
SOURCE_FREE_FORM_INPUT |
|
SOURCE_CHOICE |