Invoke SHARE for BB10

BlackBerry 10 Cascades Share BBM Twitter Facebook

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

Page {
    Container {
        Label {
            text: "What is your favorite food?"
        }
        TextField {
            id: field1
        }
        Label {
            text: "What is your favorite drink?"
        }
        TextField {
            id: field2
        }
    }
}

The two obvious answers to the questions are “Pizza” and “Beer”…

BlackBerry 10 Cascades Label TextField

Now to add the SHARE invocation:

    actions: [
        InvokeActionItem {
            ActionBar.placement: ActionBarPlacement.OnBar
            title: "Share"
            query {
                mimeType: "text/plain"
                invokeActionId: "bb.action.SHARE"
            }
            onTriggered: {
               
            }
        }
    ]

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):

BlackBerry 10 Cascades Share Action

Now to add info from you app into the onTriggered:

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:

BlackBerry 10 Cascades Share Invocation

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.

BlackBerry 10 Cascades Back Action

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!

-Brian

P.S. I’d like to thank my friend Jeremy Duke (@BerryInformed) for helping me with this code!