public final class RemoteInput
extends Object implements Parcelable
| java.lang.Object | |
| android.app.RemoteInput | |
一个RemoteInput对象指定要从用户收集的输入,以及发送的PendingIntent内部的意图。 始终使用RemoteInput.Builder来创建此类的实例。
有关如何使用此课程的更多信息,请参阅 Receiving Voice Input from a Notification 。
以下示例将RemoteInput添加到Notification.Action ,将结果键设置为quick_reply ,并将标签设置为Quick reply 。 系统会提示用户在触发操作时输入回应。 结果与intent一起发送,可以从getResultsFromIntent(Intent)返回的Bundle中使用结果键(提供给RemoteInput.Builder构造函数)进行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();
当PendingIntent被触发时,如果收集到内部的意图将包含输入结果。 要访问这些结果,请使用getResultsFromIntent(Intent)函数。 结果值将显示在传递给RemoteInput.Builder构造函数的结果键下。
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);
}
Nested classes |
|
|---|---|
class |
RemoteInput.Builder |
常量(Constants) |
|
|---|---|
String |
EXTRA_RESULTS_DATA 额外添加到剪辑数据意图对象以保存结果包。 |
String |
RESULTS_CLIP_LABEL 标签用于表示用于远程输入传输的剪辑数据类型 |
Inherited constants |
|---|
android.os.Parcelable
|
Fields |
|
|---|---|
public static final Creator<RemoteInput> |
CREATOR |
公共方法(Public methods) |
|
|---|---|
static void |
addResultsToIntent(RemoteInput[] remoteInputs, Intent intent, Bundle results) 使用从远程输入收集的结果填充意向对象。 |
int |
describeContents() 描述此Parcelable实例的封送表示中包含的特殊对象的种类。 |
boolean |
getAllowFreeFormInput() 获取用户是否可以为输入提供任意值。 |
CharSequence[] |
getChoices() 获得可能的输入选择。 |
Bundle |
getExtras() 通过此远程输入获取附加的元数据。 |
CharSequence |
getLabel() 收集此输入时获取标签以显示给用户。 |
String |
getResultKey() 当发送 |
static Bundle |
getResultsFromIntent(Intent intent) 从意图获取远程输入结果包。 |
void |
writeToParcel(Parcel out, int flags) 将此对象平铺到一个包裹中。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
android.os.Parcelable
|
|
String EXTRA_RESULTS_DATA
额外添加到剪辑数据意图对象以保存结果包。
常量值:“android.remoteinput.resultsData”
String RESULTS_CLIP_LABEL
标签用于表示用于远程输入传输的剪辑数据类型
常量值:“android.remoteinput.results”
void addResultsToIntent (RemoteInput[] remoteInputs, Intent intent, Bundle results)
使用从远程输入收集的结果填充意向对象。 此方法只应在远程输入收集服务将结果发送给挂起的意图时调用。
| 参数(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 result per key. |
int describeContents ()
描述此Parcelable实例的封送表示中包含的特殊对象的种类。 例如,如果对象将在writeToParcel(Parcel, int)的输出中包含writeToParcel(Parcel, int) ,则此方法的返回值必须包含CONTENTS_FILE_DESCRIPTOR位。
| 返回(Returns) | |
|---|---|
int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. |
boolean getAllowFreeFormInput ()
获取用户是否可以为输入提供任意值。 如果你将其设置为false ,用户必须选择其中一个选项getChoices() 。 如果IllegalArgumentException设置为false并且getChoices()返回null或为空,则会null 。
| 返回(Returns) | |
|---|---|
boolean |
|
CharSequence[] getChoices ()
获得可能的输入选择。 如果没有null选择的话,这可以是null 。
| 返回(Returns) | |
|---|---|
CharSequence[] |
|
String getResultKey ()
当发送 getResultsFromIntent(Intent)时, PendingIntent从 getResultsFromIntent(Intent)返回的Bundle中设置此输入结果的密钥。
| 返回(Returns) | |
|---|---|
String |
|
Bundle getResultsFromIntent (Intent intent)
从意图获取远程输入结果包。 返回的Bundle将包含由远程输入收集器填充的每个结果键的键/值。 使用getCharSequence(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 |
|
void writeToParcel (Parcel out, int flags)
将此对象平铺到一个包裹中。
| 参数(Parameters) | |
|---|---|
out |
Parcel: The Parcel in which the object should be written. |
flags |
int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. |