background image

Using the BlackBerry Browser

Display content in the BlackBerry Browser

To display web content in the BlackBerry® Browser, use the 

net.rim.blackberry.api.browser

 package.

Display content in a BlackBerry Browser field

To display web content in a BlackBerry® Browser field, use the 

net.rim.blackberry.api.browser

 package.

Display content in the BlackBerry Browser
Display content in a BlackBerry Browser field
Code sample

Task

Steps

Retrieve a BlackBerry® Browser session.

Retrieving the default session overrides any open sessions on the 

BlackBerry device

.

>

Retrieve the default 

BrowserSession

 object by invoking the static method 

Browser.getDefaultSession()

Retrieve 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 excerpt from the Restaurants.java sample creates 
a menu item that displays a web page in the BlackBerry Browser. 
private MenuItem browserItem = new 
MenuItem(_resources.getString(MENUITEM_BROWSER), 110, 12) {
public void run() {
synchronized(store) {String websiteUrl = 
websitefield.getText();
if (websiteUrl.length == 0) {
Dialog.alert(_resources.getString(ALERT_NO_WEBSITE));
} else {
BrowserSession visit = Browser.getDefaultSession();
visit.displayPage(websiteUrl);

}

};

Task

Steps

Access a rendering session.

1.

Invoke 

RenderingSession.getNewInstance().

2. Store the returned rendering session handle in a

 RenderingSession

 object.

RenderingSession _renderingSession = RenderingSession.getNewInstance();.

Содержание 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...

Отзывы: