Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecognizerIntent: how to add a bundle to a pending intent

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

Paraphrasing the documentation:

  • 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.

  • 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.

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?

like image 807
Kaarel Avatar asked Jun 24 '11 10:06

Kaarel


1 Answers

You can not directly touch the contents of a PendingIntent, for security reasons. However, when you send the PendingIntent, you have the opportunity to supplement or modify its contents depending on what the original creator allows.

This is the method you want to use to send the PendingIntent:

http://developer.android.com/reference/android/app/PendingIntent.html#send(android.content.Context, int, android.content.Intent, android.app.PendingIntent.OnFinished, android.os.Handler)

The Intent you supply here is the data used to modify the final Intent sent from the PendingIntent.

The rules for what can be modified are here:

http://developer.android.com/reference/android/content/Intent.html#fillIn(android.content.Intent, int)

Note that by default when a PendingIntent is created, the only parts that can be modified by the sender are the extras. The creator can pass in flags to allow other parts to be modified, although this is generally not desired.

like image 91
hackbod Avatar answered Sep 23 '22 11:09

hackbod