The designers of BlackBerry 10 and Cascades wanted an experience where the user never leaves an app, rather flows from one application to another. That is done using the invocation framework. One of the easiest things to do is to share something from inside of your app to a wide variety of other apps on the device (such as BBM, Facebook and Twitter). See past the break how easily this can be done!
UPDATE: Confirmed that this will invoke all applications with share such as Twitter, Facebook, email and SMS (texting) on a full version BB10 device.
Let’s start by making a simple UI with two Labels and two TextFields:
import bb.cascades 1.0
text: "What is your favorite food?"
text: "What is your favorite drink?"
The two obvious answers to the questions are “Pizza” and “Beer”…
Now to add the SHARE invocation:
It should be inside the actions array, as an InvokeActionItem. Setting the mimeType to “text/plain” will invoke any Card that is of that type. That mimeType will call Cards for apps such as SMS (text), email, BBM, BBM Group, Facebook, Twitter, etc. Currently only BBM, BBM Group, and NFC appear on the DevAlpha but I have been told once the user has other apps mentioned above, they will appear as well. So you should see the following (you even get the icon for free):
Now to add info from you app into the onTriggered:
data = "My favorite meal is " + field1.text + " and " + field2.text + "! Shared using Brian's Example app!";
What this does is grab some plain text (the stuff in the quotes) and info from the field1.text and field2.text. Now run this code and you should see the following:
Follow through the invocation share menu, the BBM card, and the last picture above shows the message sent to my Bold 9900.
After that click the Back button to return to the app.
You do not need to include any permissions in the bar-descriptor.xml as you are calling app Cards and not actually giving the app you are writing access to things like BBM or internet. More importantly now that you know how easy this is, be sure to add share functionality to all your apps!
P.S. I’d like to thank my friend Jeremy Duke (@BerryInformed) for helping me with this code!