Using BlackBerry ID in your PlayBook Application

Posted on March 24, 2011 | 3 comments

The latest release of the PlayBook’s BlackBerry Tablet OS SDK for AIR provides some new APIs. One of the newer BlackBerry APIs is around getting BlackBerry ID information. You can test the API calls that integrate the PlayBook user’s BlackBerry ID information in your application.

This is what it looks like for a user to sign into their BlackBerry ID from the PlayBook simulator (this is a system dialog and developers can’t change it):

BlackBerry ID PlayBook Sign In

To prompt the “sign in” dialog and receive the BlackBerry ID information for the user of the PlayBook see the following ActionScript API. I went ahead and wrote up some simple code to show how it works (also available in my github here):

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       applicationComplete="windowedapplication1_applicationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
           
            import net.rim.blackberry.bbid.BBIDProfile;
            import net.rim.blackberry.bbid.UserProperty;
            import net.rim.blackberry.events.BBIDEvent;
            private var bbidprofile:BBIDProfile;

            protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
            {
                bbidprofile = new BBIDProfile();
                bbidprofile.addEventListener(BBIDEvent.SUCCESS, bbidOK);
                bbidprofile.addEventListener(BBIDEvent.ERROR, bbidFailed);
            }
           
            private function bbidOK(event:BBIDEvent):void {
                bbidprofile.getToken("BBIDv1", "urn:blackberry.com", gotBBIDToken, bbidFailed);
                bbidprofile.getUserProperties(["username"], gotProps, bbidFailed);
            }
           
            private function gotProps(properties:Array, data:* = null):void {
                for each(var prop:UserProperty in properties) {
                    log("Got user property: " + prop);
                }
            }
           
            private function gotBBIDToken(token:String, tokenResponseParams:Array, data:* = null):void {
                // Use token and tokenResponseParams (array of TokenParam) to make service call.
                log("gotBBIDToken: " + token);
            }
           
            private function bbidFailed(message:String, data:* = null):void {
                // Log error message and show the user an application error
                log("Error: " + message);
            }
           
            private function log(msg:String):void
            {
                output.text += msg + "\n";
            }

        ]]>
    </fx:Script>
    <s:layout>
        <s:VerticalLayout />
    </s:layout>
    <s:TextArea id="output" width="100%" height="100%" />
</s:WindowedApplication>

Note signing into the Simulator with your BlackBerry ID doesn’t seem to work for me, if it does work for you please let me know.

  • Mariano carrizo

    Great! I want to know how you created the project using mxml code like any standard air windowed application. How you compile them?
    Yesterday I finished my first playbook app (I’m waiting developer certificates from RIM to send it), and I used AS project with playbook sdk to build them, but I would love to use mxml, spark and the powerful of skinning with fxg!
    Could you please explain me how to do that? Did you test performance using flex compared to native sdk in real device?
    Thanks Renaun! I’m following you to learn about it!

    • http://www.renaun.com Renaun Erickson

      Flex works great on the device. Just use Flash Builder Burrito and Flex mobile projects.

  • http://us.blackberry.com/playbook-tablet/ tablet

    Great!Thank you!