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_PENDINGINTENTEXTRA_RESULTS_PENDINGINTENT_BUNDLE
Paraphrasing the documentation:
-
If you use
EXTRA_RESULTS_PENDINGINTENTto supply aPendingIntent, the results will be added to its bundle and thePendingIntentwill be sent to its target. -
If you use
EXTRA_RESULTS_PENDINGINTENTto supply a forwarding intent, you can also useEXTRA_RESULTS_PENDINGINTENT_BUNDLEto 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.
I have been looking in vain for sample code that would demonstrate the following.
What is the best way of extracting a PendingIntent from a bundle?
Should I do:
(PendingIntent)
extras.getParcelable(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT)
How to add extras to the set of existing extras of a PendingIntent?
How to launch the modified PendingIntent?
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
PendingIntentto theRecognizerIntentwhen 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.What is the best way of extracting a
PendingIntentfrom a bundle?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.
How to launch the modified
PendingIntent?We send off the
PendingIntentgiving it the new intent (with the new extras) as an argument.