An introduction to BlackBerry Hybrid development

Application designer and developer are freely to choose which technologies to use when building blackberry solution: java or web.

Java applications are deployed directly in the device and provides very high level of interoperability with native systems and use a huge set of powerful java APIs. These type of application tends to be very powerful and functionality however the developers and designer should spent some times to design an attractive user interface, on the other side, the web application (widget) can be used to describe any content that can be access by a web browser. These type of application is easy to design and develop because is based on standard web technologies, that are well common by developer, but provides a less integration with the device. They cannot access the most of the blackberry java APIs.

Feature Java Web
Easy to design user interface no yes
Ability to integrate with native system yes low
Dependency on network coverage no yes

The concept of hybrid blackberry applications, that is the merging of java development and web development technologies, to get the best from both world, is an emerging reality nowadays. Developer can build powerfully java application that combines the use of embedded browser object with the functionalities provided by the native blackberry device software.
By using an embedding browser object as a presentation layer for your application you can read web content from local or from the net and uses to display attractive UI. You can reuse your knowledge and your code based on HTML, JavaScript, Ajax, SVG, and CSS technologies to build your application interface, while you “backend” is in java. Your application still remain a java application, so you can access the file system, messaging, and push. The recent improvements to the platform through the BrowserField2 API and BlackBerry Widget SDK represent the next evolution of hybrid BlackBerry application development, as well as providing developers with a way of easily creating their own Super Apps.

The old way

Before JDE 5.0, you had only one way to add web content to your application: BrowerField APIs.
The BrowerField APIs provide the ability to include web content inside your java application. This api include two classes the RenderingSession and the BrowserField. These classes are used together to dynamically retrieve web content in local or remote location and display it in a field on screen. It is a common missconcept that this api provide the same functionality of the native blackberry browser, such as JavaScript integration, cookies handling, redirect, and so on. BrowserField simple provide a way to download and rendering web content. If you are interesting on handling cookies for example, you must add additional code to provide the cookies management.
The additional cookie management code will need to handle storing the cookies, applying correct domain matching policies, and expiring the cookies appropriately. Moreover you should correctly pass any valid cookies along with a new request…
Cookies, caching, server side redirect, headers it a brief list of thing that you should manually handling when using the BrowserField 1.0 APIs.
You can learn more on the net.rim.device.api.browser.field looking at the sample applications, BrowserContentManagerDemo and BrowserFieldDemo, that demonstrates how to create a web browser using the old API. The samples application are distributed in the sample folder of each JDE installation.

WARNING:
BrowserField 1.0 may fails to rendering some page on older devices, keep in mind this aspect if you intend to display “untested” or arbitrary web page on this field.

Introducing Browser Field 2 API

Introduced in blackberry JDE 5.0 the new Browser APIs included in the package net.rim.device.api.browser.field2 adds important improvement on the embedded browsing area. The new api called Browser Field 2 exists alongside the old api and not replace the previous embedded browser api. The most important improvement Browser Field 2 API has over Browser Field API is that it is use the same rendering engine of  native browser. Layout Engine determines how web content is rendered.

BlackBerry Browser Layout Engine Overview

Original – introduced in 4.1, still exists in 5.0
Mango – name for new engine introduced in 4.6

Device Software Native Browser BrowserField1 BrowserField2
4.2 Original Original n/a
4.2.1 Original Original n/a
4.5 Original Original n/a
4.6 Mango Original n/a
4.7 Mango Original n/a
5.0 Mango Original Mango

This is a very important changes, it ensure that a web content displayed in application will look similar to web content rendered in the native browser application running on 4.6 device or later.

Moreover it introduces new functionality that developer immediately have at disposition. Same of this functionalities include built-in cookie manager as well browser history support, that enable you backward and forward navigation. Developer can now access the internal JavaScript engine, so you can run arbitrary JavaScript at runtime from your java application. Developer also now have accessing to DOM and have the ability to get and set DOM objects.

Feature BrowserField1 BrowserField2
Send GET/POST request for a web resource yes yes
Render web content to the screen yes yes
built-in cookie manager no yes
history collection and management no yes
Access to JavaScript engine no yes
Access to the DOM no yes
Error Handling no yes
Built in listener no yes

8 thoughts on “An introduction to BlackBerry Hybrid development

  1. Pingback: Digging into BlackBerry Hybrid development | Danilo Ercoli's Blog

  2. Pingback: 2010 in review | Danilo Ercoli

  3. Mathews

    Thanks for providing such a wonderful information but I need to handle cookies on 4.2, could you please help me to find out way for this handling.

    Reply
    1. Danilo Post author

      check out the BB development guide 4.2.1 (http://docs.blackberry.com/en/developers/subcategories/?userType=21&category=Development+Guides&subCategory=&url=/developers/subcategories/&versionId=1). There is an example called “Code sample: Using the BlackBerry Browser”. This could help you to handle cookies.
      Also, you should look within the blackberry examples, starting from 4.2.0 till to the 4.7.0 version. Examples are available within the eclipse component packages, and within the JDE installation.

      Reply
  4. Francisco

    Hello,

    I have a stack of screen, at one point one of my screen is only composed of a browserField (Screen to Connect to share on Twitter for exemple)

    So there is an input in the webPage.

    If i use the physical keyboard on the input field it works fine

    Now, if a click on the input by touching it, it launchs the virtual keyboard, and everything in my browser except the input Field disapear causing the previous screen in the stack to show.

    It doesn’t happen in a 5.0 simulator,

    I can’t test on a 6.0 simulator because BrowserField seems not to work in 6.0 simulator.
    Anyway it doesn’t work on a 6.0 device.

    Thanks for your help

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s