📜 ⬆️ ⬇️

Creating applications for BlackBerry smartphones using WebWorks SDK

image
The BlackBerry WebWorks SDK compares favorably with among other tools currently available for creating BlackBerry applications in that it allows you to develop for both smartphones starting with BB OS 5.0 and Playbook tablets.
In a nutshell, BlackBerry Web Apps or “web widgets” is a platform based on HTML5, CSS3 and extensible JS standards. It seems to be "sparsely" for writing a decent application, but the first impression is deceptive. Below it becomes clear why. It should be noted that the version of the API for tablets Playbook is still very different from the full, but is actively developed and supplemented, the documentation is updated with intensive frequency. In this article we will give examples using the capabilities of a full-fledged API, i.e. supported in BB OS 6 and 7, and in the next we describe the process of developing widgets for the Playbook.

BlackBerry WebWorks Stuffing


Starting with the sixth version of the operating system for smartphones, the browser engine has become webkit, replacing the Java-based browser. On the Playbook tablet webkit browser is set as native initially. In aggregate, this circumstance alone makes it possible to make extensive use of the possibilities of the HTML5 + CSS3 bundle, whose support is limited in other browsers. The second and main factor is the javascript extension, a blackberry object, which provides access to interact with system and device resources located outside the application. These resources are divided into categories that are present in the naming of the corresponding embedded objects:



One example will be brighter than many words - below is a demonstration of how using javascript to create a new contact, write to the address book, and send an e-mail notification to the addressee of the newly created contact:
<script type="text/javascript"> //    var contact = new blackberry.pim.Contact(); contact.firstName = 'John'; contact.lastName = 'Doe'; contact.homePhone = '555-555-5555'; contact.email1 = 'john@doe.com'; contact.save(); //     var message = new blackberry.message.Message(); message.toRecipients = contact.email1; message.subject = ' '; message.body = ',  '; message.send(); </script> 

')
It is important to note two additional points. First, BBM Social Platform also announced support at the BlackBerry Web Apps level, which will allow integrating a popular service into its applications. Secondly, if the WebWorks API is not enough for the application, the javascript functionality can be extended with Java tools.

A bit about js frameworks and libraries


A small lyrical digression.
When creating a new application, the question almost certainly arises as to which javascript library or framework to use. The mobile framework should at least be able to handle touch events, respond to the gyro state and understand gestures.
In searching for an answer to this question, the following list may be useful:

If it seemed that the list is too small, then you can also look at microjs.com
The choice of the framework is often associated with the objectives, goals and architecture of the project, as well as with the personal preferences of the developer. We use XUI and Sencha Touch in our work. XUI js is a tiny extensible framework of only 9.4 Kb in size (or 4.1 Kb with gzip compression) with jQuery syntax. In the future, we are planning experiments with Mootools, which supports mobile devices starting from version 1.3. YUI3 is developing, by the way, in the same direction.

Setting up the development environment


You can develop web widgets in both MS Visual Studio and the Eclipse IDE. We will describe an example using Eclipse (Windows).
First you need to download Java SE 6 JDK 32-bit and configure the necessary plugins. These are WTP , BlackBerry WebWorks plug-in, and BlackBerry WebWorks SDK plug-in:

image

Plugins are available to registered developers at www.blackberry.com/go/eclipseUpdate/3.6/web . During the installation of plug-ins, you must specify a username and password.

Writing the first BlackBerry Web App


Everything, Eclipse is configured, you can create a new project called HabrHelloWidget:

image

image

The newly created project has the following structure:
build\
ext\
config.xml
index.html


The ext directory is reserved for javascript extension by java, it stores jar archives. The build directory contains project builds, it is not visible in the Eclipse Package Explorer.
The index.html file is a regular html document with the exception of the viewport meta tag. The configuration file config.xml contains a description of the application, data on the version, license, author, list with network connections in order of decreasing priority, etc. It also contains security settings when running an application with js extensions (blackberry object). The application adheres to the principle of the Same Origin Policy (SOP), so all the necessary functionality should be listed for each of the domains, including the local resource, i.e. application itself:
image

image

If the required feature (feature) is not specified in the settings, the application will raise an exception.

In the project you need to add an icon in png format and specify the path to it in config.xml. By default, the icon can be named icon.png and is located at the root of the project. Guideline to OS 6 requires that the size of the icon does not exceed 68x68 px. Dimensions of the icon for the Playbook tablet - 86x86, on this device, the automatic scaling will occur on the smartphone.

Add an icon, styles (paint the background in blue, text in white) and write a script that displays the PIN and IMEI of the device, and also displays in the loop information about the available transport protocols. For the Local resource, we announce the blackberry.identity extension available.

Markup html (index.html):
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" id="viewport" content="height=device-height,width=device-width,user-scalable=no" /> <link rel="stylesheet" href="css/style.css" /> <title>-  </title> </head> <body> <h1>, Habr!</h1> <div id="device"></div> <script type="text/javascript" src="js/init.js"></script> </body> </html> 


Initialization Script (js / init.js):
 /** * HabrHelloWidget init */ (function() { var device = document.getElementById('device'), str = ''; try { var transportList = blackberry.identity.getTransportList(); for ( var i = 0, max = transportList.length; i < max; i++) { str += "Transport name is:" + transportList[i].name + "<br />transport type:" + transportList[i].type + '<br />'; } str += "<br />PIN: " + blackberry.identity.PIN + "<br />IMEI: " + blackberry.identity.IMEI; } catch (e) { str = '   !'; } device.innerHTML = str; })(); 


Building and running on a smartphone simulator


Next, we call the context menu of the project, select the Build BlackBerry WebWorks Project option and build the project:
image
larger

We start the simulator: the context menu of the project - Run As - BlackBerry Simulator. We admire the result:

image
larger

image
larger

Testing and debugging


For projects focused on smartphones with BB OS 5, Debug As mode is available through the context menu of the project.
For the sixth version, debugging, apparently, is not yet supported, so handicraft tools like try-catch constructions, log output using the capabilities of blackberry.io.dir and blackberry.io.file objects are used . The developer forum provides examples of debugging in both Eclipse and Visual Studio.
With the tablet things are much better. Since the widget runs to the context of the webkit browser's executable environment, a web inspector can be used for debugging. Details are in the next article.

Signature of the application


To publish to AppWorld, you need to register as a vendor, and the application must be signed with digital keys. Key Request Form: www.blackberry.com/SignedKeys
A bank card with online payments is required. It takes an average of 2-3 days to receive the keys by e-mail.

A key signing application guide is available at docs.blackberry.com/en/developers/deliverables/27261/Install_the_new_registry_key_with_Signature_Tool_1582584_11.jsp

The signed application can be sent to the AppWorld for consideration and published after approval.

Subject references

Source: https://habr.com/ru/post/119675/


All Articles