background image

BlackBerry Java Development 
Environment

Version 4.6.0

BlackBerry Device Applications Integration Guide

Summary of Contents for 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: ...MERCHANTABILITY DURABILITY TITLE OR RELATED TO THE PERFORMANCE OR NON PERFORMANCE OF ANY SOFTWARE REFERENCED HEREIN OR PERFORMANCE OF ANY SERVICES REFERENCED HEREIN IN CONNECTION WITH YOUR USE OF THIS...

Page 3: ...Published in Canada Research In Motion Limited 295 Phillip Street Waterloo ON N2L 3W8 Canada Research In Motion UK Limited Centrum House 36 Station Road Egham Surrey TW20 9LF United Kingdom...

Page 4: ......

Page 5: ...8 Notify an application that an email message is about to be sent 20 Notify an application that an MMS message is about to be sent 20 Notify an application that an SMS message is about to be sent 20 S...

Page 6: ...e Displaying a screen that lets BlackBerry device users add new contacts 45 Code sample Using tasks 48 5 Using the phone application 51 Start the phone application from your BlackBerry Java Applicatio...

Page 7: ......

Page 8: ...public class SampleMenuItem extends ApplicationMenuItem Specify the position of the menu item in the menu A higher number means that the menu item appears lower in the menu Invoke ApplicationMenuItem...

Page 9: ...Java Application menu item Invoke the constructor ContactsDemoMenuItem contactsDemoMenuItem new ContactsDemoMenuItem Add the menu item to the repository Invoke ApplicationMenuItemRepository addMenuIte...

Page 10: ...10 BlackBerry Device Applications Integration Guide...

Page 11: ...o invoke BlackBerry device applications Invoke BlackBerry applications Task Steps Start the message application and create a new blank message Invoke the invokeApplication method with the following pa...

Page 12: ...12 BlackBerry Device Applications Integration Guide...

Page 13: ...XT_MESSAGE m setAddress sms 5558888 m setPayloadText An SMS Message for you 2 Invoke invokeApplication with the following parameters APP_TYPE_MESSAGES a constant parameter MessageArguments a new Messa...

Page 14: ...lank PIN message Invoke invokeApplication using the APP_TYPE_MESSAGES constant parameter and a new MessageArguments object that uses the ARG_NEW_PIN parameter Invoke invokeApplication Invoke APP_TYPE_...

Page 15: ...for batch updates Implement StoreListener batchOperation void batchOperation StoreEvent e Perform action when messages added or removed in batch operation Add a listener to a folder 1 Retrieve the Fo...

Page 16: ...o instanceof String String body String o 4 Invoke getBodyText on a message to retrieve the plain text contents as a String If the message does not contain plain text the method returns null Get more...

Page 17: ...e MimeBodyPart store the content type of the BodyPart object in a String variable if bp instanceof MimeBodyPart String type bp getcontentType 5 Check if the content type of the BodyPart object is text...

Page 18: ...rt i 6 If a BodyPart object is of type MimeBodyPart store the content type of the BodyPart object in a String variable if xp instanceof MimeBodyPart String type xp getcontentType 7 Check if the conten...

Page 19: ...ART_MIXED for int i 0 i mp getCount i BodyPart bp mp getBodyPart i if bp instanceof MimeBodyPart MimeBodyPart mbp MimeBodyPart bp Multipart mp Multipart mbp getContent if mp getcontentType equals Cont...

Page 20: ...ion e System out println e toString 5 Add a SendListener instance store addSendListener mailSL Notify an application that an MMS message is about to be sent 1 Create a class that implements net rim bl...

Page 21: ...o the method 2 If the message has multiple types of recipients invoke addRecipients once for each recipient type msg addRecipients Message RecipientType TO toList Specify the name and email address of...

Page 22: ...resents the messaging transport protocol Transport trans Session getTransport Invoke Message reply Boolean and specify true to reply to all message recipients or false to reply to only the sender Stor...

Page 23: ...Address toList 0 new Address clyde warren blackberry com Clyde Warren fwdmsg addRecipients Message RecipientType TO toList Specify that the message content appears before the original message Invoke...

Page 24: ...list int and provide as a parameter the folder type Folder folders store list INBOX Folder inbox folders 0 Retrieve an array of folders through a search Invoke findFolder String Folder folders store...

Page 25: ...tenttype 1 true false Define the associated menu item string to display in the messages list when the BlackBerry device user selects an attachment Implement menuString public String menuString return...

Page 26: ...mentPart object designating the Multipart object as its parent SupportedAttachmentPart attach new SupportedAttachmentPart multipart application x example filename data Add each SupportedAttachmentPart...

Page 27: ...e null EventList el EventList PIM getInstance openPIMList PIM EVENT_LIST PIM READ_WRITE Enumeration events el items e Event events nextElement 2 Invoke Invoke invokeApplication APP_TYPE_CALENDAR Cale...

Page 28: ...he Event Invoke invokeApplication Invoke APP_TYPE_CALENDAR new CalendarArguments CalendarArguments ARG_NEW e 4 Use an instance of the EventList class to access the calendar 5 Create one or more Event...

Page 29: ...operties and values that you can set such as COUNT FREQUENCY and INTERVAL 2 To retrieve an array of supported fields invoke RepeatRule getFields 3 To define a recurring pattern invoke setInt int int o...

Page 30: ...dex id fieldIds index if e getPIMList getFieldDataType id STRING for int j 0 j event countValues id j String value event getString id j System out println event getFieldLable id value Export an appoin...

Page 31: ...Create a class that implements the PIMListListener3 interface public class myEventListListener3 implements PIMListListener3 Import an appointment 1 To return an array of PIMItem objects invoke from Se...

Page 32: ...llLists PIM listPIMLists EVENT_LIST Using the address book Open the address book from your BlackBerry Java Application Use contacts Task Steps Open the address book From a BlackBerry Java Application...

Page 33: ...en a contacts list 1 Create a contacts list ContactList contactList null 2 Invoke PIM openPIMList and provide as parameters the type of list to open PIM CONTACT_LIST and the access mode with which to...

Page 34: ...me Contact NAME_PREFIX Mr name Contact NAME_FAMILY McPherson name Contact NAME_GIVEN Scott catch IllegalArgumentException iae handle exception Add name if contactList isSupportedField Contact NAME con...

Page 35: ...Dr newname Contact NAME_SUFFIX Jr contact setStringArray Contact NAME 0 Contact ATTR_NONE newname To change the contacts fields that support multiple values before adding another value verify that th...

Page 36: ...le enum hasMoreElements Contact c Contact enum nextElement int fieldIds c getFields int id for int index 0 index fieldIds length index id fieldIds index if c getPIMList getFieldDataType id Contact STR...

Page 37: ...pportedSerialFormats PIM CONTACT_LIST ByteArrayOutputStream byteStream new ByteArrayOutputStream Enumeration e contactList items while e hasMoreElements Contact c Contact e nextElement PIM getInstance...

Page 38: ...istListener interface public class myContactListListener implements PIMListListener 2 To register to receive notifications of changes to a contact list invoke BlackBerryPIMList addListener BlackBerryP...

Page 39: ...SKS constant parameter and a new TaskArguments object created using the ARG_VIEW parameter and the ToDo object Invoke invokeApplication Invoke APP_TYPE_TASKS new TaskArguments TaskArguments ARG_VIEW t...

Page 40: ...2 To retrieve the field data type invoke PIMList getFieldDataType int 3 To set the field data invoke one of the following methods addString addDate addInt addBoolean addBinary if todoList isSupportedF...

Page 41: ...task was last saved invoke isModified 2 Invoke commit if task isModified task commit Retrieve task information 1 To retrieve an enumeration invoke PIMList items on the task list ToDoList todoList ToD...

Page 42: ...byteStream UTF8 dataFormats 0 Import a task 1 To return an array of PIMItem objects invoke fromSerialFormat The enc parameter specifies the character encoding to use when writing to the output stream...

Page 43: ...ndees 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 Example EventDemo...

Page 44: ...ion add _location _startTime new DateField Start System currentTimeMillis 3600000 DateField DATE_TIME _endTime new DateField End System currentTimeMillis 7200000 DateField DATE_TIME add new SeparatorF...

Page 45: ...if index 1 rule setInt RepeatRule FREQUENCY RepeatRule WEEKLY if index 2 rule setInt RepeatRule FREQUENCY RepeatRule MONTHLY if index 3 rule setInt RepeatRule FREQUENCY RepeatRule YEARLY return rule p...

Page 46: ...ew ContactScreen pushScreen _contactScreen Inner class Creates a Screen to add a contact public static final class ContactScreen extends MainScreen private EditField _first _last _email _phone _pin pr...

Page 47: ...List createContact String name new String contactList stringArraySize Contact NAME Add values to PIM item if firstName equals name Contact NAME_GIVEN firstName if lastName equals name Contact NAME_FAM...

Page 48: ...api system import net rim device api util public final class TaskDemo extends UiApplication private TaskScreen _taskScreen public static void main String args new TaskDemo enterEventDispatcher private...

Page 49: ...TODO_LIST PIM WRITE_ONLY ToDo task todoList createToDo task addDate ToDo DUE ToDo ATTR_NONE _due getDate task addString ToDo SUMMARY ToDo ATTR_NONE _summary getText task addString ToDo NOTE ToDo ATTR_...

Page 50: ...50 BlackBerry Device Applications Integration Guide...

Page 51: ...onefield getText if phoneNumber length 0 Dialog alert _resources getString ALERT_NO_PHONENUMBER else PhoneArguments call new PhoneArguments PhoneArguments ARG_CALL phoneNumber Invoke invokeApplication...

Page 52: ...status as an string int status call getStatus if status PhoneCall STATUS_CONNECTED status PhoneCall STATUS_CONNECTING call isOutGoing elapsedTime threshold Use getCallId to retrieve the caller ID as a...

Page 53: ...int A call goes on hold callHeld int A new call arrives callIncoming int The BlackBerry device initiates an outgoing call callInitiated int A call is removed from a conference call callRemoved int A...

Page 54: ...tring phoneType PhoneCallLogID getType Create a call log or conference call log The PhoneCallLogID constructor removes dashes and other non numeric characters from phone numbers 1 Create an instance o...

Page 55: ...a participant public int findTimeSpokenTo PhoneCallLogID participant long folder int numberOfCalls this _logs numberOfCalls folder int timeSpokenTo 0 PhoneCallLog phoneCallLog ConferencePhoneCallLog c...

Page 56: ...56 BlackBerry Device Applications Integration Guide...

Page 57: ...trieve a non default BlackBerry Browser session Invoke Browser getSession Request a web page Invoke BrowserSession displayPage String url specifying the URL that contains the web content The following...

Page 58: ...on screen invoke MainScreen add _mainScreen add field 3 Create a non main event thread to run BrowserContent finishLoading so that the UI does not lock 4 To render the new BlackBerry browser content i...

Page 59: ...rs urlRequestedEvent getPostData event this thread start break case Event EVENT_BROWSER_CONTENT_CHANGED The browser field title might have changed so we update the title field BrowserContentChangedEve...

Page 60: ...erFieldSampleApplication extends UiApplication implements RenderingApplication private static final String REFERER referer private RenderingSession _renderingSession private MainScreen _mainScreen pri...

Page 61: ...case Event EVENT_URL_REQUESTED UrlRequestedEvent urlRequestedEvent UrlRequestedEvent event String absoluteUrl urlRequestedEvent getURL HttpConnection conn null PrimaryResourceFetchThread thread new P...

Page 62: ...referrer HttpConnection eventSource getRequestProperty REFERER break HttpHeaders requestHeaders new HttpHeaders requestHeaders setProperty REFERER referrer PrimaryResourceFetchThread thread new Prima...

Page 63: ...eturn 0 see net rim device api browser RenderingApplication getHTTPCookie java lang String public String getHTTPCookie String url no cookie support return null see net rim device api browser Rendering...

Page 64: ...able Runnable runnable new Thread runnable run class PrimaryResourceFetchThread extends Thread private BrowserFieldSampleApplication _application private Event _event private byte _postData private Ht...

Page 65: ......

Page 66: ...2008 Research In Motion Limited Published in Canada...

Reviews: