RecognizerIntent:如何将包添加到待处理的意图

编程入门 行业动态 更新时间:2024-10-26 06:29:34
本文介绍了RecognizerIntent:如何将包添加到待处理的意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我实现了响应RecognizerIntent.除其他这项活动必须处理指定挂起的意图和两个输入额外的及其的演员束:

I am implementing an activity that responds to the RecognizerIntent. Among others this activity must handle two incoming extras that specify a pending intent and its extras-bundle:

  • EXTRA_RESULTS_PENDINGINTENT
  • EXTRA_RESULTS_PENDINGINTENT_BUNDLE
  • EXTRA_RESULTS_PENDINGINTENT
  • EXTRA_RESULTS_PENDINGINTENT_BUNDLE

复述的文档:

  • 如果您使用 EXTRA_RESULTS_PENDINGINTENT 提供一个 PendingIntent ,其结果将被添加到其捆绑并在 PendingIntent 将被发送到它的目标。

  • If you use EXTRA_RESULTS_PENDINGINTENT to supply a PendingIntent, the results will be added to its bundle and the PendingIntent will be sent to its target.

如果您使用 EXTRA_RESULTS_PENDINGINTENT 来提供一个转发的意图,你也可以使用 EXTRA_RESULTS_PENDINGINTENT_BUNDLE 来提供额外的额外的最终意图。搜索结果将被添加到该束中,并将合并的束将被发送到目标

If you use EXTRA_RESULTS_PENDINGINTENT to supply a forwarding intent, you can also use EXTRA_RESULTS_PENDINGINTENT_BUNDLE to supply additional extras for the final intent. The search results will be added to this bundle, and the combined bundle will be sent to the target.

我一直在寻找是徒劳的样品code,将表现出以下。

I have been looking in vain for sample code that would demonstrate the following.

什么是解压的最佳方式 PendingIntent 从包?

What is the best way of extracting a PendingIntent from a bundle?

我应该做的:

(PendingIntent) extras.getParcelable(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT)

如何额外添加到组现有额外的 PendingIntent ?

How to add extras to the set of existing extras of a PendingIntent?

如何启动修改 PendingIntent ?

How to launch the modified PendingIntent?

推荐答案

这些是我目前这些问题的答案。它的工作原理是这样的一些谷歌应用程序(地图,文档,YouTube,听)的,所有通过 PendingIntent 到 RecognizerIntent 当你执行通过话筒按钮搜索。我不能确定,虽然这是否是做的最好(或最一般的)的方式。任何意见,欢迎。

These are my current answers to these questions. It works like this in a number of Google apps (Maps, Docs, YouTube, Listen) which all pass the PendingIntent to the RecognizerIntent when you perform the search via the microphone button. I am unsure though if this is the best (or most general) way of doing it. Any comments are welcome.

什么是解压的最佳方式 PendingIntent 从包?

What is the best way of extracting a PendingIntent from a bundle?

Parcelable extraResultsPendingIntentAsParceable = bundle.getParcelable(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT); if (extraResultsPendingIntentAsParceable != null) { if (extraResultsPendingIntentAsParceable instanceof PendingIntent) { mExtraResultsPendingIntent = (PendingIntent) extraResultsPendingIntentAsParceable; } else { // Report an error } } mExtraResultsPendingIntentBundle = bundle.getBundle(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE);

如何额外添加到组现有额外的 PendingIntent ?

How to add extras to the set of existing extras of a PendingIntent?

在这里,我们只需要创建一个新的意图,并把所有需要的额外内容。

Here we just create a new intent and put all the required extras into it.

if (mExtraResultsPendingIntentBundle == null) { mExtraResultsPendingIntentBundle = new Bundle(); } Intent intent = new Intent(); intent.putExtras(mExtraResultsPendingIntentBundle); // Unsure about the following line... // Should I use another name for the extra data (instead of SearchManager.QUERY) intent.putExtra(SearchManager.QUERY, speechRecognitionResult);

如何启动修改 PendingIntent ?

How to launch the modified PendingIntent?

我们欢送 PendingIntent 赋予它新的意图(新演员)作为参数。

We send off the PendingIntent giving it the new intent (with the new extras) as an argument.

try { mExtraResultsPendingIntent.send(this, 1234, intent); } catch (CanceledException e) { // Handle exception }

更多推荐

RecognizerIntent:如何将包添加到待处理的意图

本文发布于:2023-11-27 04:38:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   意图   RecognizerIntent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!