我实现了响应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:如何将包添加到待处理的意图
发布评论