PhoneGap: BlackBerry

needlessoybeanMobile - Wireless

Dec 10, 2013 (3 years and 6 months ago)

75 views

PhoneGap:
BlackBerry

Java, J2ME, RIM’s
browser implementation

Fil Maj

Web & Mobile Development

Nitobi

Overview of the SDKs and
PhoneGap support


Many versions…


Before 4.6. Lack of
‘experimental’ rendering in the
browser (more on this later).
PhoneGap? Nope.


4.6. The minimum version of
the SDK that we can support.
Yes!


4.7 aka Storm. We’re good.


5.0 and beyond… Things are
looking good, but we still need
to implement. SDK *just* got
released.


The SDKs boil down to J2ME
plus a proprietary library
developed by RIM
-
> not open
-
source. Sadface.

Overview of the
BlackBerry Market
(late 2009)


Fragmented.


4.2 and below: about 30%; All models up to the early Pearl
(BlackBerry 8230)


4.2 to 4.6.1: about 30%; Later Pearl models up to the Bold
(BlackBerry 8230 to 9000)


4.6.1, 4.7 and up: about 30%; Recent models like the Bold, the
Storm and the Tour.


PhoneGap applications can realistically target about
50% of all BlackBerry devices right now; this number can
only grow in the future.

What Can We Do On A BlackBerry?


PhoneGap API, pretty much everything the iPhone
can… except:


Accelerometer. SDK access came recently (Storm, Storm 2
and Tour are only models that have accelerometer at this
time)



Browser is limited.
Limited DOM
implementation and
primitive JavaScript
error handling. More
on this in a bit.

Standards: We’ve seen this problem before

For PhoneGap to achieve its goal, it needs to have a consistent API across
platforms.

BlackBerry Browser
Implementation


Support for ‘experimental’ rendering necessary. Only
available for recent SDKs, main reason for exclusion of
old models. This came up on StackOverflow…


A lot of JavaScript and the DOM implementation, which
is mostly standards
-
compliant, works in the BlackBerry
browser application, but is
NOT

available in the Field aka
Web View.


DOM
Level 2

only
.


Certain events not supported; i.e. onchange


For changes between level 3 and level 2, check out the W3C spec:
http://www.w3.org/TR/DOM
-
Level
-
3
-
Core/changes.html



CSS
Level 2

only
.


XHR does
NOT

work. It’s ok though. We’ve implemented our
own in Java and added an interface to it via JavaScript.

Device & Browser Nuances


We’ve said this before: simulator != device


Just on the Bold 9000 model:


Onkeyup event is not recognized but in the simulator it works.


setInterval basically works like setTimeout


probably because the
browser’s JavaScript doesn’t have reliable timing.


One issue came up after the first on
-
device deployment with
rendering. Details and solution on my blog.


The Browser has two rendering modes. Column View:


Native resolution of most BlackBerries is 480x320 or 480x360.
Storm is the exception as it is 360x480.


Column View ‘tricks’ the browser into thinking the screen
resolution is 1024x768, then scales everything down to match
the native resolution of the particular device.


Column View will also wrap any content


Obviously, pixel perfect is extremely difficult.


… and Page View.
Page View is better
. Simply add:

<meta name=“HandheldFriendly” content=“True” />

to the <head> of your PhoneGap page to trigger Page
View.

PhoneGap BlackBerry Architecture
/ Design


Follows Command pattern


device functionality
encapsulated in commands:
TelephonyCommand, GeoLocationCommand,
MediaCommand, etc.



Message
passing done via
cookies. We can
capture both
setting and
getting a cookie
in the browser
from the native
end.

PhoneGap Resource Handling


PhoneGap BlackBerry works by
instantiating a mini Java browser
and feeding it content to display.


We can only feed it HttpConnection
objects, so we have to use Java’s
magical Connector.open function to
create these objects.


We trick the connector to open an
HTTP connection to a resource on
the device by feeding it a Base64
-
encoded data URI of the local
resource.


Can take a while to do this in
-
real
-
life
-
on
-
the
-
device, even with
caching. For performance reasons,
best to keep your entire application
on one page.

PhoneGap Architecture
Code

public String processInstruction(String instruction) {


for (int index = 0; index < commands.length; index++) {


Command command = (Command) commands[index];


if (command.accept(instruction))


try {


return command.execute(instruction);


} catch(Exception e) { }


}


return null;

}

public interface Command {



String execute(String instruction);



boolean accept(String instruction);

}


Development Experience

The good: object statistics and memory
profiler.

Garbage collection! Win, right?
Well, maybe not: profiler tells a
different story.

Object handles and memory
aren’t cleaned up properly,
even if you explicitly call the
garbage collector with
System.gc()

You need to explicitly set
objects to null once you are
done with them to keep your
memory footprint acceptable.

Does this even count as
Garbage Collection? .. Not
really.

Still Need More Testing


We haven’t tested the
entire DOM and
JavaScript
implementation.


We have developed
and tested a few
applications, but only
on one device for now:
The BlackBerry Bold.


Open
-
Source project


shameless plug. Want to help?
Fork the repo from GitHub!

The Future Looks Good


RIM JDE 5.0 (recently went gold) seems to be a
significant improvement over previous SDKs.


Browser implementation to get better


DOM and CSS level 3!


Widget SDK is another avenue, and is exactly how device
manufacturers can engage web developers in their application
ecosystem, but it turns out there are no sensor APIs available
(i.e. accelerometer, vibration)

Useful Developer Resources


The RIM documentation… but where is it?


Bluntly: their site is useless. Use Google:


‘blackberry browser documentation’


The supported HTML, JavaScript and CSS for
each SDK version of the browser.


‘blackberry api documentation’


The BlackBerry Developer forums are
extremely active and informative. Excellent
community.

BlackBerry Application Deployment


App World

-

Administrative
fun to get on here


Apply for signature keys ($$)


Apply as a Vendor ($$ & time)


Submit an application for
approval ($20 a submission)


RIM QA team outsources the
testing (10 business day turn
around time).



Over
-
the
-
air deployment.



A common distribution method for a lot of mainstream BlackBerry
applications like Evernote, Facebook.



Host the compiled binary (.jar or .cod files) on a web server and
serve the files up with a specific MIME type (
application/java
-
archive jar,

application/vnd.rim.cod cod).



Direct downloads then possible straight from the device.

Questions / Comments?


E
-
mail me:
filip.maj@nitobi.com


Blog:
http://blogs.nitobi.com/fil


Latest BlackBerry
PhoneGap hackery:
http://github.com/phoneg
ap/phonegap
-
blackberry