BlackBerry
Skip Top Navigation
Developers Partners
North America [change region] Products Solutions Purchasing Support
Developers


Connecting to the Network

Exercise

Write an application that retrieves a text file over the network using HTTP.

Objectives

  • Discover how to use the Mobile Data Service (MDS) simulator.
  • Discover how to open an HTTP connection
  • Discover how to retrieve data over an HTTP connection and display it.

Setup

  1. Download the file
  2. In the IDE, open the http_request.jdw workspace
  3. Open the HTTPFetch.java source file.

Tasks

  1. Change the SAMPLE_PAGE constant to define the test page to retrieve. Ask your instructor for this information.
  2. Create a ConnectionThread object.
  3. In the ConnectionThread inner class, add code to open the connection and retrieve the data.
  4. In the HTTPFetch constructor, start the connection thread and invoke the fetchPage method.
  5. Add code to the fetchPage method to invoke ConnectionThread.fetch().
  6. Add code to the updateContent method to display the text that has been retrieved on the screen.
  7. Add code to the onExit method to stop the connection thread.
  8. Create the application constructor.
  9. Start the Mobile Data Service (MDS) simulator.
  10. Build and run the application.

Check Your Work

Download the completed code

Review

In this exercise, you discovered the following things:

  • how to use the MDS simulator to test network connectivity
  • how to open an HTTP connection and retrieve data
  • how to display retrieved data on the user interface


Additional Labs

Go to the first exercise in “Developing User Interfaces for BlackBerry”, Introduction to User Interface managers

Back to the Developer Lab Main Menu

 
Other Resources
 
     
 Home | Products | Solutions | Purchasing | Support | Developers | Worldwide | News | About Us | Contact Us | Site Map
 Legal | Copyright © 2008 Research In Motion Limited, unless otherwise noted.