developing custom java applications blackberry

33
Developing Custom Java™ Applications for BlackBerry® Tariq Tahir Madrid, 25 th October 2007

Upload: praveen

Post on 11-Apr-2015

11.488 views

Category:

Documents


3 download

DESCRIPTION

Developing_Custom_Java_Applications_ BlackBerry.pdf

TRANSCRIPT

Page 1: Developing Custom Java Applications  BlackBerry

Developing Custom Java™ Applications for BlackBerry ®

Tariq TahirMadrid, 25th October 2007

Page 2: Developing Custom Java Applications  BlackBerry

Agenda

• Introduction to Java™ and Java ME• Overview of the Java APIs for BlackBerry®

– User Interface & Persistent Data Storage• Expandable Memory

– Wireless Transport & Push• WiFi

– Application Integration• Multimedia Playback & Streaming

• Camera

• GPS & BlackBerry® Maps

– Sneak Preview of JDE v4.3

• BlackBerry IDE and Simulators

Page 3: Developing Custom Java Applications  BlackBerry

• Java ME is a standard set of Java libraries, designed to be run on constrained devices– Restricted subset of Java SE API libraries– Has been adopted by major handset vendors and network

operators worldwide– Device manufacturers provide device-specific API extensions

• Java on BlackBerry– BlackBerry® smartphones run a Java-based operating

environment– Full support for Java ME standard (MIDP 2.0/CLDC 1.1)– BlackBerry-specific Java API and transport extensions

• Enables applications to leverage unique features of BlackBerry smartphones and service for simplified and enriched mobile application development for the enterprise

– Applications are developed with:• BlackBerry Java Development Environment (JDE)• Eclipse/NetBeans (JDE Component Package)

Introduction to Java and Java ME

Page 4: Developing Custom Java Applications  BlackBerry

Java on BlackBerry

• BlackBerry JDE v4.0 (Fall 2004)– Full featured Integrated Development Environment (IDE) with

simulators– Includes full support for Java ME MIDP 2.0/CLDC 1.1– Includes BlackBerry-specific Java API extensions– Supports all BlackBerry devices running v4.0+ handheld code

• BlackBerry JDE v4.1 (Fall 2005)– Enhanced Java API set and new IDE features– Support for Debugging in Eclipse

• BlackBerry JDE v4.2 (Fall 2006)– New API enhancements (many specific to new hardware in

BlackBerry Pearl smartphone)• BlackBerry JDE v4.2.1 (Spring 2007)

– Advanced API’s for multimedia and WiFi– Bluetooth®, Security & Trust, Enhanced BlackBerry Maps API

Note: JDE is forwards-compatible with Handheld Software versions

Page 5: Developing Custom Java Applications  BlackBerry

Java on BlackBerry

• Java APIs for BlackBerry enable you to develop custom client applications that provide:– Customizable user interface– Local data storage on the device – Event listening and system interfaces– Standards-based, secure wireless transport

• Communicate with back-end application or web servers via HTTP / TCP

For more advanced applications:– Integration with BlackBerry Email, PIM and Phone applications– Always-on background threads to listen for push data– Location-based services and audio playback– Integration with Media Player and Camera

Page 6: Developing Custom Java Applications  BlackBerry

Core Java APIs Available for BlackBerry Applications

User InterfaceData Storage

Wireless Transport and PushBlackBerry Application Integration

Location-Based Services & BlackBerry MapsCamera & Multimedia

Page 7: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:User Interface

• User Interface APIs allow you to:– Add screen objects to the display– Add fields and menus to the screen– Add a key listener to the screen and use

navigation API’s• Act on user trackball/key events

• Various screens and field types are available:– MainScreen, PopupScreen, Dialog– EditField, ListField, RadioButtonField, etc.

• Refer to the BlackBerry applications on the device to see what you can do!

Page 8: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:User Interface – Tips

• Each screen can be its own class, responsible for implementing its own menu items, fields and event listening

• Screens are pushed onto and ‘popped’ off of a UI stack• Menu items are self-contained runnable objects

class CallReportDetailsScreen extends MainScreen

{

private DateField callDate;

private ObjectChoiceField callResult;

public CallReportDetailsScreen() //Constructor: called when object is created

this.add(callDate); //Add fields to the screen

this.add(callResult);

MenuItem submit = new MenuItem(“Submit”) //”Submit” menu item

public void run ()

httpThread myHttp = new httpThread(); //Sends data to server via HTTP

myHttp.start()

UiApplication. popScreen (UiApplication.getActiveScreen); //Close this screen

Page 9: Developing Custom Java Applications  BlackBerry

• New Navigation APIs in JDE v4.2– Support for 4-way trackball on Pearl and future devices– Replaces trackwheel APIs– Abstract implementation supports both trackwheel and trackball

navigation

TrackBall – 4-way navigation – ‘Click’ (5-way)

EndSend

EscapeFull Menu

BlackBerry Java APIs:User Interface – Tips

Page 10: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:Persistent Data Storage

• Data can be stored locally on the device• Data persists across application instances and device resets• There are 3 options for persistently storing data:

– MIDP RMS (Java ME standard): Store data records as raw byte arrays

– PersistentStore (BlackBerry): Store Java objects directly to memory

– JSR-75: File Connection API to store data in expandable memory

class Customer implements Persistable //This object can be added to PersistentStore

private String name;

private String address;

private String phone;

public void setName(String newName)

name = newName;

public String getName()

return name;

Page 11: Developing Custom Java Applications  BlackBerry

• Key things to consider during application development:– Managing Objects and Object Handles

• Too many objects can cause you to run out of memory quickly• Object grouping reduces the number of object handles used

– Designing and Managing Persistent Data Structures• Optimize data structures and use indices for faster searching• Use primitives instead of objects like Vector when possible

– Use Objects Window in IDE debugger to monitor object creation

BlackBerry Java APIs:Persistent Data Storage – Tips

Page 12: Developing Custom Java Applications  BlackBerry

• Key things to consider during application development:– Garbage Collection

• BlackBerry JVM Garbage Collector (GC) automatically removes stale objects from memory

• GC requires system resources and can impact user experience, help Garbage Collector by minimizing number and size of objects used

– Using the Low Memory Manager• Low Memory Manager (LMM) monitors low memory conditions, takes

care of deleting old emails and calendar entries to free up space• Java applications can listen for low memory conditions and can

volunteer data to be deleted when memory is low

– Refer to the Memory Management Best Practices Whitepapers on BlackBerry Developer Zone for more information

BlackBerry Java APIs:Persistent Data Storage – Tips

Page 13: Developing Custom Java Applications  BlackBerry

• JSR 75: File Connection API in v4.2 supports storing and retrieving data from the local file system

– javax.microedition.io.file– Access internal memory:

FileConnection fconn = (FileConnection)Connector.open("file:///store/home/user/audio/newfile.mp3");

– Access microSD card:FileConnection fconn =

(FileConnection)Connector.open("file:///SDCard/music/newfile.mp3");

– Listen for new files:FileSystemRegistry.addFileSystemListener();

• Use System.getProperty() for location of default directory paths

BlackBerry Java APIs:Expansion Memory

Page 14: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:Network Communications

• Java ME defines HTTP as the standard network transport protocol– BlackBerry supports HTTP via the BlackBerry® Enterprise Server™ with

Mobile Data Service (MDS) for pull- and push-based connections– Supports any content-type over the HTTP transport, including XML

• BlackBerry also supports a variety of other transport protocols and gateway options, including:

– HTTP via carrier-hosted gateway– TCP sockets and SSL– Programmatically sending / receiving email and PIN-to-PIN messages– SMS

• Use the Coverage Info API starting in v4.2.0• HTTP via MDS should be used for most enterprise applications

Page 15: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:Network Communications

HTTP Request via BlackBerry Enterprise Server with MDS:

Wireless BlackBerry Enterprise Server with MDS

Web/App ServerJava Client Internet / Intranet

BlackBerry / AES HTTP(S)

URL=“http://webServer1.MyCompany.com/bbApps/callRep ort/submit”;HttpConnection http = (HttpConnection)Connector.open (URL);DataOutputStream.write(myData.getBytes()); //Write o ut dataDataIpoutStream in = http.openInputStream(); //Read i n response

int httpStatus = http.getResponseCode(); //Read HTTP S tatus

URL=“http://webServer1.MyCompany.com/bbApps/callReport/ submit” ;HttpConnection http = (HttpConnection)Connector.open (URL);DataOutputStream.write(myData.getBytes()); //Write out dataDataIpoutStream in = http.openInputStream(); //Read in response

int httpStatus = http.getResponseCode(); //Read HTTP Status

Page 16: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:Network Communications – Push

• Server-side applications can push data to custom client applications– HTTP POST connection to MDS, write out the contents of the push

– Can be written in any server programming language, provided it supports HTTP transport (Java/Java EE, .NET/C#, etc.)

• Push application is written in same way as browser push application and can leverage same features– Address destination user via email address or device PIN– Content is typically XML or plain text, rather than HTML

• Consider BlackBerry push features:– BlackBerry Push vs. PAP Push

– Reliable Push, Delivery-Before <timestamp> and other features available in BlackBerry Enterprise Server v4.0+

Page 17: Developing Custom Java Applications  BlackBerry

Client and server sample code for push:

Client

App:

Class httpListen extends Thread

run() {

URL=“http://:5500”; //Arbitrary local port

notify = (StreamConnectionNotifier)Connector.open( URL);

StreamConnection stream = notify.acceptAndOpen() ;

… }

Server

App:

URL = “http://myBesMDS.myCo.net:8080/push? [email protected]&PORT=5500” ;myHttpConnection.setRequestMethod(“POST”);out = myHttpConnection.getOutputStream();out.write(myData);

Wireless BlackBerry Enterprise Server App/Web ServerJava App

HTTP POST

BlackBerry Java APIs:Network Communications – Push

Page 18: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:Network Communications – Tips

• Key things to consider during application development:– Transport model for server-initiated updates

• Push? Poll? “Poke and Pull”? Persistent Connection?

• Push is most efficient for wireless applications

• Polling models are untimely and require additional traffic• Persistent Connections require additional traffic to keep data

connections active, even if there is no new data to send

– Managing Data Synchronization and Offline Storage• Transaction queuing (managing data submitted while out of coverage)

• Reliability and conflict resolution (factor for both client and server)• Back-end integration (middleware, protocols/APIs, etc.)

• Data format (XML can simplify development, but requires more data)

• Leveraging reliable and managed push

Page 19: Developing Custom Java Applications  BlackBerry

• True Least Cost Routing for Data (Seamless!)• Connection Capabilities

– Via BlackBerry Infrastructure– Via MDS (Access Point on Corporate Network or

VPN to Corporate Network)– DirectTCP via Access Point

• Voice Support only via UMA• WLANConnectionListener

– Notification of connected and disconnected events• WLANInfo

– Add/Removes listeners and determines state• WLANAPInfo

– Access point information• Connector.open enhancements

– Force a connection to use a direct TCP through an Access Point by appending “;inferface=wifi” to the URL

BlackBerry Java APIs:Network Communications – WiFi

Page 20: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:Application Integration – Email, PIM & Phone

• BlackBerry APIs enable Java applications to access emails, contacts, calendar and tasks on the device– Read, write and update

• Applications can add custom menu items to the Email, Contacts, Calendar, MemoPad, Tasks, Browser, BlackBerry Maps and Phone applications– Your application is called with a reference to the item that the user

has selected

• Applications can also register listeners for email and PIM events, as well as phone calls and inbound SMS messages

• Applications can invoke the BlackBerry applications– Programmatically launch the Phone, Browser, Email, Contacts,

Calendar, Tasks, Memopad, BlackBerry Maps, Multimedia Player and Camera applications

Page 21: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:Application Integration – Options

• BlackBerry Options application provides a central location for user configuration items

• Applications can register an options item to contain application-specific configuration

• To add an options item:– Implement the OptionsProvider interface

– Register implementation with OptionsManager

Page 22: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:Application Integration – Notification Profiles

• Notification Profiles specify how to alert the user when certain events occur

– For example, tone or vibrate the device when a new email arrives

– Provides a single location for managing different notification settings for all applications

• Java applications can provide the ability to set notifications for their application through the central Profiles application

• Allows user to manage alert settings for ALL applications without opening each application

Page 23: Developing Custom Java Applications  BlackBerry

BlackBerry Java APIs:GPS Location-Based Services

• Several devices have local GPS chips– BlackBerry 8800, 8820, 8310 (EDGE/GPRS)– BlackBerry 7130e, 8703e, 8830, 8130 (CDMA)– BlackBerry 7520 and 7100i (iDEN)– These handhelds support JSR-179: Location API for Java ME

• GPS support for devices for Bluetooth capable devices– Connect GPS peripherals to device via Bluetooth– BlackBerry v4.0/v4.1

• Applications must implement custom Bluetooth connections

– BlackBerry v4.2• Seamless support for Bluetooth GPS peripherals via JSR-179 API

Page 24: Developing Custom Java Applications  BlackBerry

• New core application with BlackBerry software v4.2

– Provides interactive, light-weight maps– Route planning– GPS mapping and tracking– Integration with native applications– www.blackberry.com/maps

• New APIs in JDE v4.2– Invoke BlackBerry Maps to a specific location

by specifying latitude/longitude coordinates• New APIs in JDE v4.2.1

– Access to geocoding engine to acquire lat/long from address

– Register custom menu items– Insert custom icons and points of interest

BlackBerry Java APIs:BlackBerry Maps Integration

Page 25: Developing Custom Java Applications  BlackBerry

• New Media APIs: v4.2.0– Invoke the Media Player via the browser for both audio and video playback– MMAPI support for audio playback (mp3, m4a/aac, amr, wav, wma)– MMAPI support for audio recording– Audio routing control

• New Media APIs: v4.2.1– MMAPI support for video playback from within 3rd party applications for

devices with Media Player application (avi, 3gp, mp4, mov, wmv)

• New Media APIs: v4.3.0– Progressive HTTP downloads

• Camera APIs (specific to BlackBerry smartphones with camera)– Ability to invoke the camera application to allow user to capture pictures– Ability to detect when new images are added to the file system (JSR-75)– Samples provided in JDE to showcase new functionality

BlackBerry Java APIs:Multimedia

Page 26: Developing Custom Java Applications  BlackBerry

• JSR 205 – Wireless Messaging 2.0 (MMS Support)• JSR 211 – Content Handler API• JSR 238 – Internationalization• JSR 172 – Web Services• Screenshot API• Media Player

– Invoke Media Player via JSR 211– Embed Video Player in RIMlets (MIDlets supported in v4.2.1)

• Expanded PIM Support• JAD Attributes Accessible from Application• Signature Tool Manual Password Requirement Removed

BlackBerry Java APIs:What’s New in JDE v4.3?

Page 27: Developing Custom Java Applications  BlackBerry

• BlackBerry JDE is available for download from BlackBerry Developer Zone

– www.blackberry.com/developers

• BlackBerry JDE includes all components necessary to build and test Java applications

– IDE, simulators, sample applications, JavaDocs– Developer Guides are downloaded separately

• Developer Zone includes additional device simulators with support for different versions of BlackBerry® Device Software

– Various builds of BlackBerry Device Software v4.1, v4.2.1, etc.– Useful for debugging device-specific problems

BlackBerry JDE:Using the IDE and Simulators

Page 28: Developing Custom Java Applications  BlackBerry

BlackBerry JDE:Using the IDE and Simulators

Workspace & Projects

Code Editor

Output Window

Page 29: Developing Custom Java Applications  BlackBerry

BlackBerry JDE:Using the IDE and Simulators

Device Simulators

MDS Simulator

Page 30: Developing Custom Java Applications  BlackBerry

IDE provides rich tools for application debugging and optimization:

• Conditional breakpoints• Process and object viewers• Memory Statistics• Code Profiler and Code Coverage tool

BlackBerry JDE:Using the IDE and Simulators

Page 31: Developing Custom Java Applications  BlackBerry

• Some APIs are protected by signing• Controlled APIs are split into four categories:

– Runtime APIs– BlackBerry Application APIs– Crypto APIs– Certicom APIs

• Signature tool signs COD files based on unique ID provided to a developer

• When the application is run the BlackBerry OS checks the application to see if it has been signed with the correct key

• http://na.blackberry.com/eng/developers/downloads/api.jsp

BlackBerry Security:Code Signing

Page 32: Developing Custom Java Applications  BlackBerry

• Application Control– Specifies what API calls are allowed– BES admin or user can set controls– Three levels of access

• Allow, prompt, deny– Application Control checks are executed when API call is

made• Can cause prompts during application execution

– JDE 4.2.1 introduced Application Control API• Allows application to query settings• Application can now control the experience• Ask user at the start of application to allow access• Updates application permissions based on user action

BlackBerry Security:Application Control

Page 33: Developing Custom Java Applications  BlackBerry

Agenda for the Day

• Introduction to Developing Wireless Applications for BlackBerry®

– Overview of development options and approaches in the enterprise

• Creating Applications using BlackBerry® MDS Studio & BlackBerry Plug-in for Microsoft® Visual Studio®

– Drag-and-drop development tools for building custom rich-client applications in the enterprise

• Developing Custom Java™ Applications for BlackBerry– Using the BlackBerry JDE to develop custom rich-client

applications using Java Micro Edition

Thank You for Attending!!

Thank You for Thank You for Attending!!Attending!!