Blackberry JAVA DEVELOPMENT ENVIRONMENT - -  DEVICE APPLICATIONS INTEGRATION - DEVELOPMENT GUIDE Integration Manual
Blackberry JAVA DEVELOPMENT ENVIRONMENT - -  DEVICE APPLICATIONS INTEGRATION - DEVELOPMENT GUIDE Integration Manual

Blackberry JAVA DEVELOPMENT ENVIRONMENT - - DEVICE APPLICATIONS INTEGRATION - DEVELOPMENT GUIDE Integration Manual

Blackberry device applications integration guide
Table of Contents

Advertisement

Quick Links

BlackBerry Java Development
Environment
Version 4.6.0
BlackBerry Device Applications Integration Guide

Advertisement

Table of Contents
loading

Summary of Contents for Blackberry JAVA DEVELOPMENT ENVIRONMENT - - DEVICE APPLICATIONS INTEGRATION - DEVELOPMENT GUIDE

  • Page 1 BlackBerry Java Development Environment Version 4.6.0 BlackBerry Device Applications Integration Guide...
  • Page 2 Send us your comments on product documentation: https://www.blackberry.com/DocsFeedback. ©2008 Research In Motion Limited. All rights reserved. BlackBerry®, RIM®, Research In Motion®, SureType® and related trademarks, names, and logos are the property of Research In Motion Limited and are registered and/or used as trademarks in the U.S., Canada, and countries around the world.
  • Page 3 Research In Motion Limited Research In Motion UK Limited 295 Phillip Street Centrum House, 36 Station Road Waterloo, ON N2L 3W8 Egham, Surrey TW20 9LF Canada United Kingdom Published in Canada...
  • Page 5: Table Of Contents

    Using the calendar ............................27 Start the calendar from your BlackBerry Java Application ............... 27 Use the calendar............................28 Notify an application when a list of events changes ................31 Notify an application when the default list of events on a BlackBerry device changes ....31...
  • Page 6 Notify an application when a list of tasks changes ................43 Code samples..............................43 Code sample: Creating new recurring appointments................ 43 Code sample: Displaying a screen that lets BlackBerry device users add new contacts .....45 Code sample: Using tasks ........................48 Using the phone application ..........................51 Start the phone application from your BlackBerry Java Application ............51...
  • Page 8: Adding Custom Menu Items To Applications

    Adding custom menu items to applications Adding menu items to BlackBerry Java Applications Adding menu items to BlackBerry Java Applications net.rim.blackberry.api.menuitem The Application Menu Item API, in the package, lets you add menu items to BlackBerry® Java® Applications. The ApplicationMenuItemRepository class lets you add or remove menu items from BlackBerry Java Applications.
  • Page 9: Register A Menu Item

    1: Adding menu items to BlackBerry Java Applications Register a menu item Task Steps ApplicationMenuItemRepository.getInstance(). Retrieve the BlackBerry® MDS Java > Invoke Application menu item repository. ApplicationMenuItemRepository repository = ApplicationMenuItemRepository.getInstance(); Create your BlackBerry Java > Invoke the constructor. ContactsDemoMenuItem contactsDemoMenuItem = new ContactsDemoMenuItem();...
  • Page 10 BlackBerry Device Applications Integration Guide...
  • Page 11: Integrating With Blackberry Applications

    Invoke BlackBerry applications Invoke BlackBerry applications You can create BlackBerry® Java® Applications that invoke BlackBerry device applications such as the email, calendar, phone, maps, browser, and camera applications to perform an action or display information. When the third-party BlackBerry Java Application invokes the BlackBerry device application, the third-party BlackBerry Java Application can make the BlackBerry device application perform an action or display information.
  • Page 12 BlackBerry Device Applications Integration Guide...
  • Page 13: Using The Message List

    Using the message list Create new messages Work with a message Work with folders Working with attachments Create new messages Task Steps invokeApplication() Create a new blank SMS text message. > Invoke using the APP_TYPE_MESSAGES constant parameter and a MessageArguments object that uses the ARG_NEW_SMS parameter.
  • Page 14 BlackBerry Device Applications Integration Guide Task Steps message Create a new populated email message. 1. Create and populate a new email object. net.rim.blackberry.api.mail.Message m = new net.rim.blackberry.api.mail.Message(); Address a = new Address("mLi@rim.com", "Ming Li"); Address[] addresses = {a}; m.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO , addresses);...
  • Page 15: Work With A Message

    FolderListener.messagesRemoved() void messagesAdded(FolderEvent e) { // Perform processing on added messages. void messagesRemoved(FolderEvent e) { // Perform processing on removed messages. net.rim.blackberry.api.mail.Store.getUnreadMessageCount() Retrieve the total count of unread > Invoke messages in all folders in the store. int numUnread = store.getUnreadMessageCount();...
  • Page 16: Open A Message

    BlackBerry Device Applications Integration Guide Task Steps Get more of a message. By default, the first section of a message (typically about 2 KB) is sent to the BlackBerry® device. BodyPart 1. Create an instance of a subclass of the abstract class.
  • Page 17: Retrieve The Body Of A Message Without An Attachment

    3: Work with a message Retrieve the body of a message without an attachment Message.getContent() Invoke Object obj=message.getContent(); Multipart Multipart 2. If the content of the message is a object, cast the message content as a object. if(obj instanceof Multipart){ Multipart mp=(Multipart)obj;...
  • Page 18: Code Sample: Retrieve The Body Of A Message

    BlackBerry Device Applications Integration Guide BodyPart MimeBodyPart Multipart 4. If the object is of type , check if the content type of the object is MULTIPART_ALTERNATIVE. if(bp instanceof MimeBodyPart){ MimeBodyPart mbp=(MimeBodyPart)bp; Multipart mp=(Multipart)mbp.getContent(); if(mp.getcontentType().equals(ContentType.MULTIPART_ALTERNATIVE){ 5. If the content type of the...
  • Page 19 3: Work with a message String type=bp.getcontentType(); if(type.equals(ContentType.TYPE_TEXT_HTML_STRING){ // HTML text else if( bp instanceof TextBodyPart){ // Plain text } //end else if }//end if }// end for loop }end if else if(mp.getContentType().equals(ContentType.MULTIPART_MIXED){ for(int i=0;i<mp.getCount();i++){ BodyPart bp =mp.getBodyPart(i); if(bp instanceof MimeBodyPart){ MimeBodyPart mbp=(MimeBodyPart)bp;...
  • Page 20: Notify An Application That An Email Message Is About To Be Sent

    BlackBerry Device Applications Integration Guide }//end if }//end for loop }//end else if Notify an application that an email message is about to be sent net.rim.blackberry.api.mail.SendListener Create a class that implements public class mailSendListener implements SendListener{ 2. Create an instance of the subclass.
  • Page 21: Send A Message

    Message"); setContent(String) Specify the message contents. > Invoke . Typically, the BlackBerry® Java® Application retrieves content from text that a BlackBerry device user types in a field. try { msg.setContent("This is a test message."); } catch(MessagingException e) { System.out.println(e.getMessage()); Session.getTransport() Send the message.
  • Page 22: Reply To A Message

    BlackBerry Device Applications Integration Guide Reply to a message Task Steps Session.getTransport() Reply to an existing message. 1. Invoke and store the returned object in a variable of type Transport Transport . The object represents the messaging transport protocol. Transport trans = Session.getTransport();...
  • Page 23: Forward A Message

    Message fwdmsg = msg.forward(); Add the recipients. 1. Create an array of addresses. Address toList[] = new Address[1]; addRecipients(int, Address[]) 2. Invoke toList[0]= new Address("clyde.warren@blackberry.com", "Clyde Warren"); fwdmsg.addRecipients(Message.RecipientType.TO, toList); setContent(String) Specify that the message content > Invoke appears before the original message.
  • Page 24 BlackBerry Device Applications Integration Guide 2. Complete any of the following actions: Task Steps store.list() Open a folder view. 1. Invoke to retrieve a list of folders. Store store = null; store = Session.waitForDefaultSession().getStore(); Folder[] folders = store.list(); nvokeApplication() 2. Invoke i...
  • Page 25: Working With Attachments

    3: Working with attachments Working with attachments To open incoming message attachments and create outgoing attachments on the BlackBerry® device, use the mail API. A separate BodyPart on a Multipart message represents a message attachment. Create an attachment handler The BlackBerry® Enterprise Server Attachment Service receives all attachments first. Third-party attachment handlers cannot override the default BlackBerry device behavior.
  • Page 26: Send A Message With An Attachment

    UnsupportedAttachmentPart the BlackBerry® device. An represents an attachment that does not have a viewer on the BlackBerry device. Send a message with an attachment Task Steps Create a multipart message.
  • Page 27: Using Pim Applications

    Using PIM applications Using the calendar Notify an application when the default list of events on a BlackBerry device changes Using tasks Code samples Using the calendar Start the calendar from your BlackBerry Java Application Task Steps Invoke.invokeApplication(APP_TYPE_CALENDAR, CalendarArguments). Open the calendar.
  • Page 28: Use The Calendar

    BlackBerry Device Applications Integration Guide Task Steps Event EventList object Open a new populated event. 1. Create a new using an Event e = null; EventList el = (EventList)PIM.getInstance().openPIMList( PIM.EVENT_LIST, PIM.READ_WRITE ); e = el.createEvent(); Event 2. Add information to the object.
  • Page 29 4: Using the calendar Task Steps isSupportedField(int) Add appointment information. > To verify that an item supports a field, invoke if (event.isSupportedField(Event.SUMMARY)) { event.addString(Event.SUMMARY, Event.ATTR_NONE, "Meet with customer"); if (event.isSupportedField(Event.LOCATION)) { event.addString(Event.LOCATION, Event.ATTR_NONE, "Conference Center"); Date start = new Date(System.currentTimeMillis() + 8640000); if (event.isSupportedField(Event.START)) { event.addDate(Event.START, Event.ATTR_NONE, start);...
  • Page 30 Export an appointment. 1. To import or export PIM item data, use an output stream writer to export tasks from the BlackBerry® device to a supported serial format, such as iCal®. 2. To retrieve a string array of supported serial formats, invoke PIM.supportedSerialFormats()
  • Page 31: Notify An Application When A List Of Events Changes

    Notify an application when the default list of events on a BlackBerry device changes When an update occurs to the list of services on a BlackBerry device, the list of organizer data databases on a device may change. This action may result in the creation of a new default list of events.
  • Page 32: Retrieve Multiple Lists Of Events

    Invoke.invokeApplication(APP_TYPE_ADDRESSBOOK, abArg); ControlledAccessException Manage exceptions. > Check for a if your BlackBerry® Java® Application invokes a BlackBerry application that you do not have permission to use or access. Use contacts Task Steps BlackBerryContact.PIN Provide access to the PIN BlackBerry® device >...
  • Page 33 BlackBerryContact.USER2 • BlackBerryContact.USER3 • BlackBerryContact.USER4 • Define labels for the USER1 through USER4 Changing a label affects all contacts on the BlackBerry device. BlackBerry® device contacts fields. BlackBerryPIMList.setFieldLabel() > Invoke Open a contacts list. 1. Create a contacts list. ContactList contactList = null;...
  • Page 34 BlackBerry Device Applications Integration Guide Task Steps Add contact information. 1. Invoke one of the following methods: addString() • addStringArray() • addDate() • addInt() • addBoolean() • addBinary() • 2. Before you set or retrieve a field, to verify that the item supports the field, invoke ContactList.isSupportedField(int)
  • Page 35 For example: if (contact.countValues(Contact.EMAIL) < contactList.maxValues(Contact.EMAIL)) { contact.addString(Contact.EMAIL, Contact.ATTR_NONE, "aisha.wahl@blackberry.com");} FieldFullException 3. Create code to manage a , which occurs if you invoke an addString() method, such as , for a field that already has a value.
  • Page 36 • To retrieve the field values, invoke PIMList.items() 3. When you invoke to retrieve an enumeration of items in a contacts list, your BlackBerry® Java® Application must sort items as necessary. ContactList contactList = (ContactList)PIM.getInstance().openPIMList( PIM.CONTACT_LIST, PIM.READ_WRITE); Enumeration enum = contactList.items();...
  • Page 37 Close a contacts list. > Invoke try { contactList.close(); } catch(PIMException e) { Dialog.alert(e.toString()); See “Code sample: Displaying a screen that lets BlackBerry device users add new contacts” on page 45 for more information.
  • Page 38: Notify An Application When A List Of Contacts Changes

    BlackBerry Device Applications Integration Guide Notify an application when a list of contacts changes PIMListListener Create a class that implements the interface. public class myContactListListener implements PIMListListener { 2. To register to receive notifications of changes to a contact list, invoke BlackBerryPIMList.addListener()
  • Page 39: Using Tasks

    4: Using tasks Using tasks Start the task application from your BlackBerry Java Application Check for a ControlledAccessException if your BlackBerry® Java® Application invokes a BlackBerry application that you do not have permission to use or access. Task Steps TaskArguments Open the task application.
  • Page 40: Use Tasks

    BlackBerry Device Applications Integration Guide Use tasks Task Steps PIM.openPIMList() Open a task list. > Invoke and provide as parameters the type of list to open PIM.TODO_LIST ) and the access mode with which to open the list (READ_WRITE, READ_ONLY, or WRITE_ONLY).
  • Page 41 4: Using tasks Task Steps Change task information. 1. To replace an existing value with a new value, invoke the appropriate set method, such as setString() countValues() 2. To determine if a value is already set for the field, invoke set() 3.
  • Page 42 Export a task. 1. To import or export PIM item data, use an output stream writer to export tasks from the BlackBerry® device to a supported serial format. 2. To retrieve a string array of supported serial formats, invoke PIM.supportedSerialFormats() PIM.TODO_List...
  • Page 43: Notify An Application When A List Of Tasks Changes

    Code sample: Creating new recurring appointments To let the BlackBerry® device user invite attendees to the meeting, combine this sample with ContactsDemo.java. See “Code sample: Displaying a screen that lets BlackBerry device users add new contacts” on page 45 for more information.
  • Page 44 BlackBerry Device Applications Integration Guide public final static class EventScreen extends MainScreen private EditField _subject, _location; private SaveMenuItem _saveMenuItem; private DateField _startTime, _endTime; private ObjectChoiceField _repeat; private Event event; private class SaveMenuItem extends MenuItem { public SaveMenuItem() { super(null, 0, 100000, 5);...
  • Page 45: Code Sample: Displaying A Screen That Lets Blackberry Device Users Add New Contacts

    Code sample: Displaying a screen that lets BlackBerry device users add new contacts The following sample demonstrates how to display a screen that lets BlackBerry® device users add new contacts to the address book. Example: ContactsDemo.java * ContactsDemo.java...
  • Page 46 BlackBerry Device Applications Integration Guide package com.rim.samples.docs.contactsdemo; import java.io.*; import java.util.*; import javax.microedition.pim.*; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.i18n.*; import net.rim.device.api.system.*; import net.rim.device.api.util.*; import net.rim.blackberry.api.pdap.*; public final class ContactsDemo extends UiApplication private ContactScreen _contactScreen; public static void main(String[] args) { new ContactsDemo().enterEventDispatcher();...
  • Page 47 4: Code samples add(_phone); _pin = new EditField(“PIN:”, ““, 8, BasicEditField.FILTER_HEXADECIMAL); add(_pin); protected boolean onSave() { String firstName = _first.getText(); String lastName = _last.getText(); String email = _email.getText(); String phone = _phone.getText(); String pin = _pin.getText(); // Verify that a first or last name and email has been entered. if ((firstName.equals(““) &&...
  • Page 48: Code Sample: Using Tasks

    BlackBerry Device Applications Integration Guide Code sample: Using tasks Example: TaskDemo.java * TaskDemo.java * Copyright (C) 2002-2005 Research In Motion Limited. package com.rim.samples.docs.taskdemo; import java.io.*; import java.util.*; import javax.microedition.pim.*; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.i18n.*; import net.rim.device.api.system.*; import net.rim.device.api.util.*;...
  • Page 49 4: Code samples _saveMenuItem = new SaveMenuItem(); setTitle(new LabelField(“Tasks Demo”, LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH)); _summary = new EditField(“Task Summary: “, ““); add(_summary); // In TODO.Priority, 0 to 9 is highest to lowest priority. String[] choices = {“High”, “Normal”, “Low”}; _priority = new ObjectChoiceField(“Priority: “, choices, 1); add(_priority);...
  • Page 50 BlackBerry Device Applications Integration Guide...
  • Page 51: Using The Phone Application

    Code sample Start the phone application from your BlackBerry Java Application To open the phone application from your BlackBerry® Java® Application, invoke Invoke.invokeApplication(APP_TYPE_PHONE,PhoneArguments) The following excerpt from the Restaurants.java code sample on page 69 creates a menu item that invokes the phone application to call a restaurant.
  • Page 52: Add Dtmf Tones To The Send Queue

    Invoke call. BlackBerry DTMF tones BlackBerry® devices play DTMF tones as soon as no other tones are pending, overriding conversations. DTMF tones consist of a low and a high frequency, which are played at the same time. Low Tone (Hz)
  • Page 53: Listen For Phone Events

    To act on a particular event, implement one of the following methods. Event Method callAdded(int) A call is added to a conference call. callAnswered(int) A BlackBerry® device user answers a call (user driven). callConferenceCallEstablished(int) A conference call is established. callConnected(int) The network indicates a connected event (network driven). callDirectConnectConnected(int) A direct-connect call is connected.
  • Page 54: Code Sample

    BlackBerry Device Applications Integration Guide Task Steps PhoneCallLogID Retrieve a call participant by phone class identifies participants in a phone call log by phone number. number. PhoneCallLog.getParticipant(int) > Invoke ConferencePhoneCallLog.getParticipantAt(). PhoneCallLogID participant = phoneCallLog.getParticipant(); PhoneCallLogID participant = ConferencePhoneCallLog.getParticipant(); honeCallLogID Retrieve the phone number type.
  • Page 55 5: Code sample import java.lang.*; import net.rim.device.api.system.Application; public class PhoneLogsDemo extends Application private PhoneLogs _logs; private int _timeSpokenTo; static public void main(String[] args) { PhoneLogsDemo app = new PhoneLogsDemo(); app.enterEventDispatcher(); private PhoneLogsDemo() { _logs = PhoneLogs.getInstance(); PhoneCallLogID participant = new PhoneCallLogID(“5551234”); _timeSpokenTo = findTimeSpokenTo(participant, PhoneLogs.FOLDER_NORMAL_CALLS);...
  • Page 56 BlackBerry Device Applications Integration Guide...
  • Page 57: Using The Blackberry Browser

    To display web content in the BlackBerry® Browser, use the package. Task Steps Retrieving the default session overrides any open sessions on the BlackBerry device. Retrieve a BlackBerry® Browser session. BrowserSession > Retrieve the default object by invoking the static method Browser.getDefaultSession()
  • Page 58 Display a BlackBerry® Browser field. 1. To clear the current screen, invoke the method. _mainScreen.deleteAll(); MainScreen.add(). 2. To add field data to the BlackBerry Java® Application screen, invoke _mainScreen.add(field); BrowserContent.finishLoading() 3. Create a non-main event thread to run so that the UI does not lock.
  • Page 59 6: Display content in a BlackBerry Browser field Task Steps RenderingApplication.eventOccurred(), Manage events. > Implement of specifying the actions that occur when a specific rendering event occurs. The following example specifies actions that occur in the event of a URL request, change in browser content, or a redirect to a different web page.
  • Page 60: Code Sample

    BlackBerry Device Applications Integration Guide Code sample Code sample: Using the BlackBerry Browser Example: BrowserFieldSampleApplication.java * DefaultRenderingApplication.java * Copyright (C) 2004-2005 Research In Motion Limited. package com.rim.samples.docs.browser; import java.io.IOException; import javax.microedition.io.HttpConnection; import net.rim.device.api.browser.field.*; import net.rim.device.api.io.http.HttpHeaders; import net.rim.device.api.system.Application; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.Status;...
  • Page 61 6: Code sample BrowserContent browserContent = null; try { browserContent = _renderingSession.getBrowserContent(connection, this, e); if (browserContent != null) { Field field = browserContent.getDisplayableContent(); if (field != null) { synchronized (Application.getEventLock()) { _mainScreen.deleteAll(); _mainScreen.add(field); browserContent.finishLoading(); } catch (RenderingException re) { } finally { SecondaryResourceFetchThread.doneAddingImages();...
  • Page 62 BlackBerry Device Applications Integration Guide RedirectEvent e = (RedirectEvent) event; String referrer = e.getSourceURL(); switch (e.getType()) { case RedirectEvent.TYPE_SINGLE_FRAME_REDIRECT : // show redirect message Application.getApplication().invokeAndWait(new Runnable() { public void run() { Status.show(“You are being redirected to a different page...”); break;...
  • Page 63 6: Code sample * @see net.rim.device.api.browser.RenderingApplication#getAvailableWidth(net.rim.device.api.brows er.BrowserContent) public int getAvailableWidth(BrowserContent browserField) { // field has full screen return Graphics.getScreenWidth(); * @see net.rim.device.api.browser.RenderingApplication#getHistoryPosition(net.rim.device.api.brow ser.BrowserContent) public int getHistoryPosition(BrowserContent browserField) { // no history support return 0; * @see net.rim.device.api.browser.RenderingApplication#getHTTPCookie(java.lang.String) public String getHTTPCookie(String url) { // no cookie support return null;...
  • Page 64 BlackBerry Device Applications Integration Guide HttpConnection connection = Utilities.makeConnection(resource.getUrl(), resource.getRequestHeaders(), null); return connection; } else { // if referrer is provided we can set up the connection on a separate thread SecondaryResourceFetchThread.enqueue(resource, referrer); return null; * @see net.rim.device.api.browser.RenderingApplication#invokeRunnable(java.lang.Runnable) public void invokeRunnable(Runnable runnable) { (new Thread(runnable)).run();...
  • Page 66 ©2008 Research In Motion Limited Published in Canada.

This manual is also suitable for:

Java development environment 4.6.0

Table of Contents