EnterpriseMobileToday BlackBerryToday

Home | News | Reviews | Features | Tips | Mobile Product Watch | Forums

Chapter Excerpt: BlackBerry Hacks - Tips & Tools

BlackBerry Hacks from O'Reillydelivers tips, tools, and other ways to best use your BlackBerry wireless handheld's phone, inbox, organizer, and browser features for phone calls, instant messaging, email, organizing, Web browsing, receiving RSS feeds, and more.

In these article, we excerpt a number of tips or hacks from the book:

  • View the Event Log
  • Put Notes in the Call Log
  • Send a Message to a Group of Users
  • Play Zork on Your BlackBerry
  • Track MDS HTTP Requests
  • Integrate the Browser into a Java App

    View the Event Log

    Your device has a hidden Event Log that can be viewed using a certain key combination.

    Similar to the event log on a Windows computer, there is an Event Log on your BlackBerry device where applications and the BlackBerry operating system itself can log information. Not only does this provide a central place to view all events from the system and applications, but it allows application developers to use an easy and consistent API for logging events so that each developer doesn't have to create his own.

    You can view the Event Log on your device and even filter certain events, copy them to the clipboard—even email the entire log to someone. You won't find an icon for the Event Log viewer program. You'll have to enter a "secret" key combination to get it to appear.

    View the Log

    From your Home screen, type the following key sequence: Alt-L,G,L,G. This should bring up the Event Log viewer as shown in Figure 1-19.


    Figure 1-19. The Event Log program

    From within the Event Log, you can view the details of each event by pressing the Enter key. Figure 1-20 shows the details of an event.

    You can copy specific events to the clipboard on your device by clicking the trackwheel when viewing the details of an event and selecting Copy Event. From the main viewer, you can copy a summary of the current day's events to the clipboard by using the trackwheel to access the menu and selecting Copy Today's Contents. Once the summary is on your clipboard, you can paste it into any other program, including in a new message, by using the trackwheel menu and choosing Paste.


    Figure 1-20. The details of a particular event

    TIP: When you access the Event Log, the program reads the current events and displays them on the screen. As you are viewing the events, additional events may have been logged since you started the program. Choose Refresh from the trackwheel menu to reread the events to make sure you're displaying the most recent events.

    Customize Event Log Options

    You can use a number of options to filter the events or even expand your view to include events that have a lower severity. To access the filter options, click on the trackwheel and choose Options from the menu. By default, the Event Log displays events with a severity of Warning. You can change the Minimum Log Level setting in your Event Log as shown in Figure 1-21.


    Figure 1-21. Changing the minimum log level

    TIP: Modifying the Minimum Log Level changes the threshold for any events that get logged after you make the change. So you cannot change the level from Warning to Information or Debug and expect to see additional events retroactively—only new events will be affected by your change. Also, consider the impact of setting the threshold to Debug Info: as with debugging logs on any platform, they can quickly fill and consume system resources.

    You can also control which applications' events show up in the Event Log. By default, the events from all applications are displayed in the Event Log. To modify which program events appear, uncheck the checkbox beside the applications you'd like to not appear in the log. Be sure and save your changes after you make modifications to the Options screen. This is useful for troubleshooting a specific application you're having problems with.

    The Event Log program also gives you the ability to clear the log. Choose Clear Log from the trackwheel menu to purge all entries in the Event Log as shown in Figure 1-22 to start from scratch when troubleshooting a problem.


    Figure 1-22. Clear the Event Log

  • Put Notes in the Call Log
  • Send a Message to a Group of Users
  • Play Zork on Your BlackBerry
  • Track MDS HTTP Requests
  • Integrate the Browser into a Java App

    About the Author
    Dave Mabe is a largely self-taught engineer and writer who strives to create a simple, elegant solution to a complex problem. He has worked in the communications industry for eight years and has worked with BlackBerry devices for almost five.


    Click to Buy

    Put Notes in the Call Log

    Save notes from your phone calls and recall that information when you need it.

    While you are on an active call with your BlackBerry, press in the trackwheel and choose "Notes" from the menu. You will be greeted with a nice clean slate of text input, ready to accept your notes, as shown in Figure 1-56.


    Figure 1-56. Adding call notes to the current call

    This will, of course, be most convenient when you're using a headset or speakerphone. The way I use this feature is that I jot down notes relevant to that call such as confirmation numbers or meeting notes, and save them. I can return to the Messages application, find the call in the list of calls I've placed, and find my notes there. From here, you can also copy text and put it into its final destination, whether an email, task, or appointment.

    If you don't remember to take notes during your call, don't fret: you can add notes to a previous call by opening the call in the Messages list and selecting "Add Notes" from the menu. If you have decided to not show calls in your Messages list, you can magically make them appear by pressing Alt-P [Hack #24]. You can then surf your messages list and get these useful little pieces of metadata and put them to use. If you discussed a budget, an invoice, or something else that you may need to reference later, make a note of it in the call and you can find this information later. If you need to remember what you talked about last time you spoke to Client X, the notes will be right there in the call detail!

    You can also highlight a phone call that has notes, click the trackwheel, and select Forward (see Figure 1-57) to forward it (notes and all) to an email address.


    Figure 1-57. Forwarding your call notes

    This lets you quickly shove the notes from that important conference call to your helpless subordinates.

    R. Emory Lundberg

  • View the Event Log
  • Send a Message to a Group of Users
  • Play Zork on Your BlackBerry
  • Track MDS HTTP Requests
  • Integrate the Browser into a Java App

    About the Author
    Dave Mabe is a largely self-taught engineer and writer who strives to create a simple, elegant solution to a complex problem. He has worked in the communications industry for eight years and has worked with BlackBerry devices for almost five.


    Click to Buy

    Send a Message to a Group of Users

    Do you have a group of people you'd like to communicate with regularly? Here are some tips for sending email or peer-to-peer (PIN) messages to several addresses.

    If you use distribution lists (DLs) to address email in the enterprise, you can use those same DLs to address email to groups of people from your BlackBerry.

    Also, it is pretty simple to create and send a PIN message to a person [Hack #27]. You can also include the PINs of several people, if you'd like the same message to go to multiple recipients. That works for an occasional message, but if you have a particular group of people to which you would like to send PIN messages frequently, you'll find yourself getting tired of adding the individual recipients each time you create a message. You cannot use an Address Book group to send PIN messages, but you can still accomplish the task in other ways!

    Use Distribution Lists

    Any distribution list can be added to your Outlook Contacts in the same manner you would add any other entry from your enterprise Global Address List (GAL). Simply select the name in the GAL or email message, right-click, and select Add to Contacts. When your contacts are synchronized with the Address Book on the handheld, those entries will be copied to your handheld, and therefore can be used to address email from the handheld. Alternatively, if you have a message that was addressed to a distribution list, that has been received on the BlackBerry handheld, you can also use that to save it in your Address Book for future use. Here's how:

    1. Open the messages list.

    2. Open a message that has been addressed to one of the distribution lists you would like to add to your Address Book.

    3. Scroll up to the To line that contains the distribution list.

    4. Click the trackwheel and select Add to Address Book.

    5. The Address Book will open and display the new entry with the email address of the DL prepopulated.

    6. Complete the remaining fields and select a name for the entry so that you can easily identify the DL in your Address Book.

    7. Click the trackwheel and select Save.

    Now you can use this DL in the To line of any message you address!

    Create a Boilerplate PIN Message

    Next, you need to create a sample PIN message and address it to a group of users. But don't send it just yet!

    1. Open the Messages application on the handheld.

    2. Click the trackwheel and select Compose PIN. The Address Book application screen appears. Select the first user you would like to include in this PIN message, click the trackwheel, and select PIN username. The Message screen appears. Enter a subject line such as "TEST PIN" for now.

    3. Now that your message is properly addressed, click the trackwheel and select Send. The Messages screen appears, and you can see your message with a checkmark to the left indicating that it has been sent.

    4. Select the sample message, click the trackwheel, and select Save. This will move your sample message to the Saved Messages application.

    TIP: If your handheld decides that it needs to delete messages to free memory, it will not delete saved messages.


    Figure 2-8. Sample PIN message addressed to three recipients

    Use Your Saved Message to Send a PIN Message

    Now you have a saved message in your saved messages application that you can use over and over to send a message to the users who were added as recipients. Simply open the Saved Messages application and locate your sample message.

    Then follow these steps:

    1. Click the trackwheel and select Open. The sample message opens.

    2. Click the trackwheel to select Reply to All.

    3. Click the trackwheel once again to select Delete Original Text.

    4. Once the message is open, modify the Subject line so that it is appropriate, and enter the body of the message you are composing.

    5. Once you are satisfied with the subject and body of your message, click the trackwheel and select Send.

    You can use this sample message over and over again. You can also modify this message to add or remove recipients at any time, or to change the PIN of a recipient.

    Shari Kornberg

  • View the Event Log
  • Put Notes in the Call Log
  • Play Zork on Your BlackBerry
  • Track MDS HTTP Requests
  • Integrate the Browser into a Java App

    About the Author
    Dave Mabe is a largely self-taught engineer and writer who strives to create a simple, elegant solution to a complex problem. He in the communications industry for eight years and has worked with BlackBerry devices for almost five.


    Click to Buy

    Play Zork on Your BlackBerry

    With this Java-based mini Infocom interpreter, you can play retro text adventures on your BlackBerry. You can even write your own games if you want!

    "Open mailbox. Take leaflet and read it." Those are the sentences you need to kick off a game of Zork, which is, to many, the prototypical text adventure. You're more likely to hear these games referred to as interactive fiction these days, and although many things have changed since the days when Infocom and Adventure International owned the genre, these games are very much alive.

    You'll find a thriving community of interactive fiction gamers and authors at the Interactive Fiction Archive (http://www.ifarchive.org/). On this site, you'll find hundreds of games, tools to create your own, and all sorts of information.

    As a text-friendly handheld, the BlackBerry is the perfect platform for interactive fiction. There are a couple of ways you can play these games on your BlackBerry. Z2ME (http://gpf.dcemu.co.uk/) is a port of ZPlet (http://sourceforge.net/projects/zplet/), a Java-based interpreter for the Z-Machine, the virtual machine that Infocom used for their interactive fiction games (compiled games are said to be in the Z-code format and have a file extension indicating which version they were compiled for, such as .z3, .z5, and so on). Many modern interactive fiction titles use the Z-Machine, so you'll find plenty of games for it. Another J2ME Z-Machine interpreter is ZeeME (http://www.gizmo-a-gogo.org/ZeeME/index.html).

    Both Z2ME and ZeeME will run fine on the BlackBerry, but there is a customized version of Z2ME that is more BlackBerry friendly. However, I was unable to get it to work on the 7100 series of BlackBerry handhelds, since Z2ME did not work correctly with the SureType input methods.

    Find Games to Play

    One of the problems with both Z2ME and ZeeME is that they come with one game (Mini-Zork). To add another game, you'll need to modify the jar file and install it on your device.

    Because there is a limit on the size of a jar file (the biggest jar I've been able to load is 76K), you need to pick small games. To see a directory listing of all the Z-code games in the interactive fiction library, visit ftp://ifarchive.org/if-archive/games/zcode/. If you open that URL up in a filesystem viewer, such as the Mac OS X Finder or Windows Explorer, you'll be able to sort by file size. Look for small Z-code files, and cross-reference what you find with the listings at Baf's Guide to the Interactive Fiction Archive: visit http://www.wurb.com/if/platform, scroll down to "Z-code," and click the link. Then you can look up a game you're interested in and read a synopsis and review. Not all games are listed, but Baf's is authoritative enough that you safely use the absence of a review as a filter. If you've got all the time in the world, though, you should try everything. There are worse things you could do with your time.

    For example, suppose 905.z5 catches your eye. It's 60.5K and might be small enough. So you head on over to Baf's, locate a review, and see that it got a decent review (four stars). Then you download the file, and use the instructions listed in the next sections to package it. Next, create a .jar (or .alx), post it on a web site for an OTA download (or use the Application Loader) [Hack #97], and start playing the game on your BlackBerry.

    TIP: If you do want to post .jad and .jar files on your own web site, make sure you have the proper MIME types set up [Hack #97].

    Use Z2ME

    Z2ME is available from http://gpf.dcemu.co.uk/ as an over-the-air installation (OTA). There are also Application Loader versions available if you have problems with the OTA install (see Phillip Bogle's post at http://www.thebogles.com/blog/2005/06/play-infocom-classics-on-your.html if you are determined to do an OTA install). When you launch Z2ME, Mini-Zork will appear. Figure 3-18 shows an intrepid adventurer doing something very wise.


    Figure 3-18. No one wants to be eaten by a grue

    Although Mini-Zork will keep you busy for a while, you might want to play some other games. It takes a bit of effort to set this up (and it's lot easier with ZeeME), but it's well worth it. Unfortunately, Z2ME only supports Inform Version 3, and you may not be able to find many compiled games in that format (Versions 5 and higher are more common). But if you search the archive (and Baf's guide), you'll find some.

    Suppose you download dejavu.z3 from the Interactive Fiction archive. You now need to rebuild the Z2ME jar file to hold this new game.

    You'll need to grab the source code to the BlackBerry version of Z2ME from http://gpf.dcemu.co.uk/ and open it in the BlackBerry JDE. Remove minizork.z3 from the project and replace it with dejavu.z3. Then, find the blackberryZ2ME.jad file in the project and change the Zfile: entry from:

    
    	Zfile: minizork.z3
    

    to:

    
    	Zfile: dejavu.z3
    

    Save and compile the project, and you'll have a jar that contains a different game.

    ZeeME

    ZeeME's user interface is a bit rougher than Z2ME's, but it supports newer Z-code files, and also has a nifty packager that lets you easily create jars of games. To use ZeeME on a BlackBerry, scroll all the way to the bottom of the screen, type your command in, and click the trackwheel to bring up the menu. Click Input, as shown in Figure 3-19, to enter your command. Be sure to use the Settings menu to set a comfortable screen width as well.

    You can download ZeeMe at http://www.gizmo-a-gogo.org/ZeeME/index.html. Both the .jar and .jad files are included on the site. Since the jar's MANIFEST contains everything ZeeME needs to know to function, you can install directly from the .jar rather than from the .jad.

    As with Z2ME, ZeeME includes Mini-Zork. If you want to run additional games, you'll need to create a separate .jar file for each of them. Also available on the ZeeME web site is the ZeeME Packager, which is a simple application you can use to create ZeeME jars (you should be able to double-click on the packager .jar file to run it). Simply specify the Z-code file, the game name, and the name of the jar you want to create, as shown in Figure 3-20.


    Figure 3-19. ZeeME's minimalist user interface


    Figure 3-20. Packaging up 905

    Post this .jar online for an OTA download (as described in "Find Games to Play"), or use the Application Loader to install it. If you need to create a .jad for it, it's pretty easy. Use jar tvfjarfile (for example, jar tvf 905.jar) to find out the name of the Z-code file (for example, zeeme/games/905.z5) and its size. You'll also need to know the size of the .jar itself.

    Set up the .jad as follows:

    
    	GameTitle0: 9:05
    	MIDlet-Jar-Size: 73066
    	GameFile0: /zeeme/games/905.z5
    	MIDlet-1: Minizork,,zmachine.ui.ZeeMEMidlet
    	MIDlet-Jar-URL: 905.jar
    	MIDlet-Version: 0.1.0
    	MIDlet-Name: 9:05
    	MIDlet-Vendor: Craig Setera
    	GameLength0: 61952

    You can also peek in the jar's META-INF/MANIFEST.MF file to get the needed values.

    Hack the Hack

    It's amazingly easy to make your own game. Graham Nelson's Inform (http://www.inform-fiction.org/) will let you create Z-code games. Here's the code for a simple game where you are trapped in a lousy place until you can get your BlackBerry working again:

    
    	Constant Story "My BlackBerry";
    	Constant Headline
    	  "^ A simple amusement^";
    
    	Include "Parser";
    	Include "VerbLib";
    	Include "Grammar";
    
    	Object battery "battery"
    	  with description "A Battery",
    	  name "battery",
    	  before [;
    		Insert:
    		  if (second == blackberry && blackberry has open) {
    		   deadflag = 2; ! indicates you've won the game
    		  }
    	  ],
    	  has concealed;
    
    	Object blackberry "BlackBerry"
    	  with name "blackberry", article "your",
    	  description [;
    	    if (self has open) {
    		  "This is a BlackBerry 7100t; it's missing a battery.";
    		} else {
    		  "This is a BlackBerry 7100t";
    		}
    	  ],
    	  before [;
    	    Open:
    			if (self hasnt open) {
    			  give self open;
    			  "You notice that the battery compartment is empty!";
    			} else {
    			  "That's already open.";
    			}
    	  ],
    	 has container openable;
    
    	Object Startroom "Street"
    	  with description
    		"This is a dark and damp street, and it doesn't feel safe.
    		 You're standing under the only streetlamp you can see
    		 for blocks. If you called someone, they'd come and
    		 pick you up.",
    	  n_to "That way doesn't feel safe.",
    	  s_to "Maybe if it wasn't so dark to the south.",
    	  w_to "It's dark that way, and you hear hungry squishing sounds.",
    	  e_to "You feel safer under the lamp.",
    	  has light;
    
    	Object rock "rock" Startroom
    	  with description "This is a damp and yucky rock.",
    	  name "rock",
    	  before [;
    	  LookUnder:
    	   if (battery has concealed) { ! It's concealed until we find it
    		  move battery to player;
    		  give battery ~ concealed;
    		  "You found a battery!";
    	   } else {
    	     "There's nothing else under the rock.";
    	   }
    	  ];
    
    	[ Initialise;
    	  location = Startroom;
    	  move blackberry to player;
    	  "^^^BlackBerry Adventure^";
    	];
    

    Download an Inform compiler and the libraries (a bunch of .h files) and copy them into the same directory. At the time of this writing, the latest Inform compiler (6.3) was creating Z-code files that were too large to create a reasonably sized .jar, so I suggest that you grab a Version 5 compiler and libraries from http://www.ifarchive.org/indexes/if-archiveXinfocomXcompilersXinform5.html.

    Save the code into a file in the same directory, and call it bbgame.inf. When you look at the contents of your working directory, if you see these files, you know you're good to go (if you're on Unix, Linux, or Mac OS X, Inform won't have an .exe extension):

    bbgame.inf

    grammar.h

    inform.exe

    parser.h

    verblib.h

    Compile bbgame.inf to a .z5 file with:

    
    	inform bbgame.inf bbgame.z5
    

    You should now have a file called bbgame.z5. Use the instructions from the previous sections to package it up in a .jar file, and play it on your BlackBerry. For more information about hacking your own interactive fiction games, see http://www.inform-fiction.org/index.html.

    Brian Jepson

  • View the Event Log
  • Put Notes in the Call Log
  • Send a Message to a Group of Users
  • Track MDS HTTP Requests
  • Integrate the Browser into a Java App

    About the Author
    Dave Mabe is a largely self-taught engineer and writer who strives to create a simple, elegant solution to a complex problem. He has worked in the communications industry for eight years and has worked with BlackBerry devices for almost five.


    Click to Buy

    Track MDS HTTP Requests

    Figure out where your users are going using the BlackBerry Browser. You may even find some useful site that you want to visit.

    Do your users use the Mobile Data Service? How frequently? Do your users go to Internet sites or intranet sites more often? Which sites are visited most?

    All these questions are interesting ones that will be different in any environment. The more data you mine from the logs will translate into more knowledge about how your users are using the service and how their experience can be improved. Perhaps an intranet application that you know has not been optimized for the BlackBerry is nevertheless being visited but not fully utilized by your BlackBerry users. You may want to go to the application developer to push for better wireless support in the web application.

    You might even see frequent access to various HTTP traffic for online games [Hack #32]. Perhaps you would want to disallow access to these and other non–business related sites.

    A single HTTP request in your MDS logs takes up at least 16 lines, and the hostname and the rest of the URL are on different lines. This makes using a simple grep command to extract the URLs impossible. Here is some Perl code that keeps track of HTTP GET requests, reconstructs the original URLs and prints them by the number of requests made to each.

    The Code

    
    	use strict;
    
    	# change the $mds_log variable to your log file
    	my $mds_log = "BESNAME_MDAT_01_20050607_0002.txt";
    
    	my $http_data = {};
    
    	open MDS, $mds_log;
    	while () {
            chomp;
    		my $id = "";
    		my $host = "";
    		my $get = "";
    		if (/EVENT = ReceivedFromDevice/ and
              /HTTPTRANSMISSION = Host:([^>]+)>/) {
                  $host = $1;
                ($id) = (/CONNECTIONID = (d+),/);
    			$http_data->{$id}->{host} = $host;
            } elsif (/EVENT = SentToServer/ and
              /HTTPTRANSMISSION = GET (.+) HTTP/1.1>/) {
                  $get = $1;
                ($id) = (/CONNECTIONID = (d+),/);
    			$http_data->{$id}->{get} = $get;
            }
    	}
    	close MDS;
    
    	my %urls = ();
    	foreach my $id (keys %{ $http_data }) {
            my $host = $http_data->{$id}->{host};
    		my $get = $http_data->{$id}->{get};
    		next if not $host and $get;
    		my $url = "http://$host" . $get;
    		$urls{$url}++;
    	}
    
    	foreach my $url (sort { $urls{$b} <=> $urls{$a} } keys %urls) {
            print "$urls{$url}	$url
    ";
        }
    

    Your MDS logs appear with your other BlackBerry logs in the following directory where YYYYMMDD is the current date (assuming you've installed your BES on the C: drive):

    
    	C:Program FilesResearch In MotionBlackBerry Enterprise ServerLogsYYYYMMDD
    

    The Mobile Data Service logs will start with your BES name followed by the string MDAT.

    
    	BESNAME_MDAT_01_20050607_0002.txt
    

    Type the code into your text editor and save it as site_extract.pl.

    Run the Code

    Bring up a command prompt, change directory (cd) to the directory where you saved the file, and type the following command to run the script:

    
    	C:>perl site_extract.pl

    You'll get a list of URLs preceded by the number of instances they appear in your logfile, as shown in the following:

    
    4	http://www.cnn.com/
    3	http://dave.runningland.com/index.php
    1	http://www.google.com/
    

    You could easily pipe the output to a file and open the data using a spread-sheet program such as Microsoft Excel.

    
    	C:>perl site_extract.pl > todays.frequent.sites.txt

  • View the Event Log
  • Put Notes in the Call Log
  • Send a Message to a Group of Users
  • Play Zork on Your BlackBerry
  • Integrate the Browser into a Java App

    About the Author
    Dave Mabe is a largely self-taught engineer and writer who strives to create a simple, elegant solution to a complex problem. He has worked in the communications industry for eight years and has worked with BlackBerry devices for almost five.


    Click to Buy

    Integrate the Browser into a Java App

    Combine the richness of a Java client with the extensibility and power of a web backend.

    Berry 411 is built using a Java client that launches a web browser. This is a powerful and convenient way to build mobile applications.

    The Java client provides instant accessibility from the Home screen and a rich native BlackBerry UI. The browser results screen allows for zero-install deployment of new features, easy display of rich text and graphics, and linking to the expanding array of mobile-friendly web content.

    The BlackBerry is especially well suited to building this sort of application. The Back button works as expected when going back from a browser page to the client application that launched it. Using the built-in browser network configuration avoids many of the configuration hassles of direct network access, which requires a number of carrier-specific parameters.

    Launch the Browser from Java

    In this hack, we'll build an application to do reverse phone number lookups, going from a phone number to a name and address. The Java client displays a titlebar and input field, filtered to limit the user's input to 10 digits. When the user selects Search from the menu (see Figure 9-4), the application launches a web page (in this case, an existing Infospace service) to display the results, shown in Figure 9-5.


    Figure 9-4. Java client


    Figure 9-5. Web results

    Even in this very simple form, the hybrid approach has advantages over a pure browser solution. The application launches instantly and has a degree of control over the user's input, which could not be achieved in a browser. It would not be difficult to extend this application to take further advantage of the rich Java client; for example, it could allow the user to select a phone number from his Address Book to look up.

    The Code

    
    	/**
    	* Reverse Phone Directory Lookup Application
    	* This sample uses a Java frontend to prompt the user for a phone
    	* number, then launches a web page to display the corresponding address.	
    	*/
    	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.collection.util.*;
    
    	public class BrowserLauncher extends UiApplication
    	{
    		public static void main(String[] args)
    		{
    			BrowserLauncher theApp = new BrowserLauncher( );
    			theApp.enterEventDispatcher( );
    		}
    
    		public BrowserLauncher( )
    		{
    			pushScreen(new SearchScreen( ));
    		}
    
    		class SearchScreen extends MainScreen
    		{
    			BasicEditField _phoneNumberEntry;
    
    			SearchScreen( )
    			{
    			
    				super(DEFAULT_MENU | DEFAULT_CLOSE);
    				setTitle(new LabelField("Reverse phone lookup",
    				LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH));
    
    				_phoneNumberEntry = new BasicEditField("Phone number: ",
    				  "", 10,
    				  BasicEditField.NO_NEWLINE | BasicEditField.FILTER_INTEGER);
    				add(_phoneNumberEntry);
    				addMenuItem(new MenuItem("Search", 1, 1) {
    				public void run( ) {
    				String phone = _phoneNumberEntry.getText( );
    				launchBrowser("http://www.infospace.com/" +
    				"_1_L5UTTJ03LEBVO_ _infow.sbcw" +
    				"/x/app/rev/detail.xhtml?top=&area=" +
    				phone.substring(0,3) + "&exchange=" +
    				phone.substring(3,6) +
    				"&phend=" + phone.substring(6,10) +"&ran=24");
    				}
    				});
    			}
    		}
    		static private boolean launchBrowser(String baseUrl)
    		{
    			boolean retval = true;
    
    			int handle =
    			  CodeModuleManager.getModuleHandle("net_rim_bb_browser_daemon");
    
    			if (handle <=0 ) {
    				retval = false;
    			}
    			else {
    				ApplicationDescriptor[] browserDescriptors =
    				CodeModuleManager.getApplicationDescriptors(handle);
    
    				if (browserDescriptors == null )
    				{
    				retval = false;
    				}
    				else {
    				if ( browserDescriptors.length <=0 ) {
    				retval = false;
    				}
    				else {
    				String[] args = {"url", baseUrl};
    				ApplicationDescriptor descriptor =
    				new ApplicationDescriptor(browserDescriptors[0],
    				"url invocation", args,
    				null, -1, null, -1,
    				ApplicationDescriptor.FLAG_SYSTEM);
    				try {
    				ApplicationManager.getApplicationManager( ).
    					runApplication(descriptor);
    				}
    				catch(ApplicationManagerException e) {
    				retval = false;
    				}
    				}
    				}
    			}
    			return retval;
    		}	
    	}
    

    Save the code as BrowserLauncher.jav'a: this is the sole class in this application. The key function is launchBrowser( ), which includes some black magic to launch the user's default browser with the requested URL. The code links to the Infospace reverse directory page, providing the user's input as parameters.

    Compile and Run the Application

    To compile this code, use the Research In Motion JDE, which you can download from the BlackBerry web site. The code has been successfully tested with Versions 3.7 and 4.0 of the JDE.

    Create a new workspace and project in the JDE, and add BrowserLauncher. java to the project. (If you'd like to save yourself the typing, you can download a ZIP archive, including the entire project, from http://thebogles.com/browserlauncher.zip.)

    Select "Go" from Debug menu, and the JDE will build the application and launch the BlackBerry simulator, including the application. You should also launch the MDS simulator from the JDE Start menu item to allow the application to access the network.

    Once the simulator is launched, you can scroll to the BrowserLauncher application on the Home screen and click on it, by using your mouse scroll-wheel. Type in a listed 10-digit phone number, click on "Search in the menu, and you should see the results displayed in the browser.

    Sign and Distribute the Application

    Launching the browser is considered a "controlled API" by Research In Motion. To run the application on a real BlackBerry, you will also need to register for a code signing key and sign the application [Hack #98].

    Phil Bogle

  • View the Event Log
  • Put Notes in the Call Log
  • Send a Message to a Group of Users
  • Play Zork on Your BlackBerry
  • Track MDS HTTP Requests

    About the Author
    Dave Mabe is a largely self-taught engineer and writer who strives to create a simple, elegant solution to a complex problem. He has worked in the communications industry for eight years and has worked with BlackBerry devices for almost five.


    Click to Buy


    Chapter Excerpt: BlackBerry Hacks - Tips & Tools