BlackBerry PlayBook Adobe AIR Developer Tips

Posted on November 12, 2010 | 7 comments

Here are a few tips for developing on the BlackBerry PlayBook with AIR:

DISCLAIMER: Some tips will change as the PlayBook OS changes. The BlackBerry Tablet OS and SDK are in beta form and will definitely change for production release.

Application Icon

In the current beta build of the BlackBerry Tablet OS SDK you can find the default icon. Its not a full PSD template but if you want to create an icon like the 3d looking box its a start for now. The icon is found at the following path relative to your blackberry-tablet-sdk-0.9.0 sdk path: {sdk_root}/samples/icons/blackberry-tablet-default-icon.png.

Browse For Image (this will likely change)

If you check CameraRoll.supportsBrowseForImage and CameraRoll.supportsAddBitmapData the currently beta simulator will say false and false. A workaround to get access to the Photo folder is do use this following code:

private var browseFile:File = new File();
protected function button2_clickHandler(event:MouseEvent):void
{
    browseFile.browseForOpen("Open File");
    browseFile.addEventListener(Event.SELECT, selectedFileHandler);
}

protected function selectedFileHandler(event:Event):void
{
    var stream:FileStream = new FileStream();
    stream.open(browseFile, FileMode.READ);
        var bytes:ByteArray = new ByteArray();
    stream.readBytes(bytes);
}

This brings up PlayBook UI like this:

Reading & Writing Files (permissions on certain folders might change over time)

Here is some code to write data to file and then read it. This is useful for pulling data off the web to store on the device (ie: images, xml, etc…).

var newFile:File = File.applicationStorageDirectory.resolvePath("myfile.txt");
trace("newFile: " + newFile.nativePath + " - " + newFile.exists);
var stream:FileStream = new FileStream();
stream.open(newFile, FileMode.WRITE);
trace("Writing Data");
stream.writeUTF("Here is some text");
stream.close();
stream = new FileStream();
stream.open(newFile, FileMode.READ);
trace("Reading Data");
var text:String = stream.readUTF();
trace(text);
  • http://probertson.com/ Paul Robertson

    Renaun,

    Thanks for all your tips on working with the PlayBook.

    On the third one (Reading and Writing files) it looks like it’s the same as with any use of the File apis in AIR — i.e. use File.applicationStorageDirectory for the app data store. Is that right? Am I missing something in your example?

    Thanks!

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

      Yeah the 3rd one isn’t unique by itself just posted for the ppl not so familiar with the AIR api, the question came up in the webinar yesterday.

  • Brian

    I’ve got the 2nd app to run with a bit of tweeking, but can you get it to actually display the picture ?

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

      Yes, but I haven’t tried it. I’ll comment if I get time to whip up some code to show how to do it.

  • http://flexr.wordpress.com Joseph

    For some reason I can’t trace, well, it’s not showing in the console. Any reason for that?

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

      Is your SWF a debug SWF? and are you launching the Flash Builder in debug mode?

  • somebody

    How do one open a files that are not recognized by playbook itself , like *.flv ?
    var flvFilter:FileFilter = new FileFilter(“FLV (*.flv)”, “*.flv”);
    does not work ?