background image

BlackBerry Java Development Environment Version 4.6.0 BlackBerry Device Applications Integration Guide

Last modified: 29 August 2008

Part number: 20595761

At the time of publication, this documentation is based on the BlackBerry Java Development Environment Version 4.6.0.

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.

Bluetooth is a trademark of Bluetooth SIG. Java and JavaScript are trademarks of Sun Microsystems, Inc. Microsoft, ActiveX, Internet Explorer, 
and Windows are trademarks of Microsoft Corporation. iCal is a trademark of Apple Computer, Inc. vCard is a trademark of the Internet Mail 
Consortium. Plazmic is a trademark of Plazmic Inc. Wi-Fi and 802.11, 802.11a, 802.11b, 802.11g are trademarks of the Wi-Fi Alliance. All other 
brands, product names, company names, trademarks and service marks are the properties of their respective owners.

The BlackBerry device and/or associated software are protected by copyright, international treaties and various patents, including one or 
more of the following U.S. patents: 6,278,442; 6,271,605; 6,219,694; 6,075,470; 6,073,318; D445,428; D433,460; D416,256.  Other patents 
are registered or pending in various countries around the world.  Visit 

www.rim.com/patents.shtml

 for a list of RIM (as hereinafter defined) 

patents.

This document is provided “as is” and Research In Motion Limited and its affiliated companies (“RIM”) assume no responsibility for any 
typographical, technical or other inaccuracies in this document. In order to protect RIM proprietary and confidential information and/or trade 
secrets, this document may describe some aspects of RIM technology in generalized terms. RIM reserves the right to periodically change 
information that is contained in this document; however, RIM makes no commitment to provide any such changes, updates, enhancements or 
other additions to this document to you in a timely manner or at all.  RIM MAKES NO REPRESENTATIONS, WARRANTIES, CONDITIONS OR 
COVENANTS, EITHER EXPRESS OR IMPLIED (INCLUDING WITHOUT LIMITATION, ANY EXPRESS OR IMPLIED WARRANTIES OR 
CONDITIONS OF FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, 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 DOCUMENTATION, NEITHER RIM NOR ITS RESPECTIVE DIRECTORS, 
OFFICERS, EMPLOYEES OR CONSULTANTS SHALL BE LIABLE TO YOU FOR ANY DAMAGES WHATSOEVER BE THEY DIRECT, ECONOMIC, 
COMMERCIAL, SPECIAL, CONSEQUENTIAL, INCIDENTAL, EXEMPLARY OR INDIRECT DAMAGES, EVEN IF RIM HAS BEEN ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGES, INCLUDING WITHOUT LIMITATION, LOSS OF BUSINESS REVENUE OR EARNINGS, LOST DATA, 
DAMAGES CAUSED BY DELAYS, LOST PROFITS, OR A FAILURE TO REALIZE EXPECTED SAVINGS.

This document might contain references to third party sources of information, hardware or software, products or services and/or third party 
web sites (collectively the “Third-Party Information”).  RIM does not control, and is not responsible for, any Third-Party Information, including, 
without limitation the content, accuracy, copyright compliance, compatibility, performance, trustworthiness, legality, decency, links, or any 
other aspect of Third-Party Information.  The inclusion of Third-Party Information in this document does not imply endorsement by RIM of the 
Third Party Information or the third party in any way.  Installation and use of Third Party Information with RIM's products and services may 
require one or more patent, trademark or copyright licenses in order to avoid infringement of the intellectual property rights of others.  Any 
dealings with Third Party Information, including, without limitation, compliance with applicable licenses and terms and conditions, are solely 
between you and the third party.  You are solely responsible for determining whether such third party licenses are required and are 
responsible for acquiring any such licenses relating to Third Party Information.  To the extent that such intellectual property licenses may be 
required, RIM expressly recommends that you do not install or use Third Party Information until all such applicable licenses have been 
acquired by you or on your behalf.  Your use of Third Party Information shall be governed by and subject to you agreeing to the terms of the 
Third Party Information licenses.  Any Third Party Information that is provided with RIM's products and services is provided "as is".  RIM makes 
no representation, warranty or guarantee whatsoever in relation to the Third Party Information and RIM assumes no liability whatsoever in 
relation to the Third Party Information even if RIM has been advised of the possibility of such damages or can anticipate such damages. 

Содержание JAVA DEVELOPMENT ENVIRONMENT - - DEVICE APPLICATIONS INTEGRATION - DEVELOPMENT GUIDE

Страница 1: ...BlackBerry Java Development Environment Version 4 6 0 BlackBerry Device Applications Integration Guide...

Страница 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...

Страница 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...

Страница 4: ......

Страница 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...

Страница 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...

Страница 7: ......

Страница 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...

Страница 9: ...Java Application menu item Invoke the constructor ContactsDemoMenuItem contactsDemoMenuItem new ContactsDemoMenuItem Add the menu item to the repository Invoke ApplicationMenuItemRepository addMenuIte...

Страница 10: ...10 BlackBerry Device Applications Integration Guide...

Страница 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...

Страница 12: ...12 BlackBerry Device Applications Integration Guide...

Страница 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...

Страница 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_...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 26: ...mentPart object designating the Multipart object as its parent SupportedAttachmentPart attach new SupportedAttachmentPart multipart application x example filename data Add each SupportedAttachmentPart...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 37: ...pportedSerialFormats PIM CONTACT_LIST ByteArrayOutputStream byteStream new ByteArrayOutputStream Enumeration e contactList items while e hasMoreElements Contact c Contact e nextElement PIM getInstance...

Страница 38: ...istListener interface public class myContactListListener implements PIMListListener 2 To register to receive notifications of changes to a contact list invoke BlackBerryPIMList addListener BlackBerryP...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 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_...

Страница 50: ...50 BlackBerry Device Applications Integration Guide...

Страница 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...

Страница 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...

Страница 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...

Страница 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...

Страница 55: ...a participant public int findTimeSpokenTo PhoneCallLogID participant long folder int numberOfCalls this _logs numberOfCalls folder int timeSpokenTo 0 PhoneCallLog phoneCallLog ConferencePhoneCallLog c...

Страница 56: ...56 BlackBerry Device Applications Integration Guide...

Страница 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...

Страница 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...

Страница 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...

Страница 60: ...erFieldSampleApplication extends UiApplication implements RenderingApplication private static final String REFERER referer private RenderingSession _renderingSession private MainScreen _mainScreen pri...

Страница 61: ...case Event EVENT_URL_REQUESTED UrlRequestedEvent urlRequestedEvent UrlRequestedEvent event String absoluteUrl urlRequestedEvent getURL HttpConnection conn null PrimaryResourceFetchThread thread new P...

Страница 62: ...referrer HttpConnection eventSource getRequestProperty REFERER break HttpHeaders requestHeaders new HttpHeaders requestHeaders setProperty REFERER referrer PrimaryResourceFetchThread thread new Prima...

Страница 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...

Страница 64: ...able Runnable runnable new Thread runnable run class PrimaryResourceFetchThread extends Thread private BrowserFieldSampleApplication _application private Event _event private byte _postData private Ht...

Страница 65: ......

Страница 66: ...2008 Research In Motion Limited Published in Canada...

Отзывы: