Wednesday, March 4, 2009

Code : Access and Obtain Service Books


The BlackBerry JDE 4.0 has a package, net.rim.device.api.servicebook, that allows the retrieval of service book information on a BlackBerry device.

The example below uses both the ServiceBook and ServiceRecord classes to obtain the APN of the WAP Browser service book:

import net.rim.device.api.system.*;
import net.rim.device.api.servicebook.*;
public class ServiceBookExample extends Application {
ServiceRecord[] _sRecordsArray; //Creates a ServiceRecord array.
ServiceBook _servicebook; //Creates a ServiceBook variable.
String cidValue, sbName, sbAPN;
public static void main(String[] args)
{
// Create a new instance of the application and
// start the event thread.
ServiceBookExample app = new ServiceBookExample();
app.enterEventDispatcher();
}
public ServiceBookExample() {
// Returns a reference to the service book from the factory.
_servicebook = ServiceBook.getSB();
// Returns an array of all registered service records.
_sRecordsArray = _servicebook.getRecords();
// Loops through the service record array
// and obtains specific information relating
// to each item and prints it to the debugging output.
for(int i = 0; i < _sRecordsArray.length; i++) {
// Obtains the Service Book CID
cidValue = _sRecordsArray[i].getCid();
// Obtains the Name of the Service Book
sbName = _sRecordsArray[i].getName();
if(cidValue.equals("BrowserConfig")
&& sbName.startsWith("WAP Browser")) {
// Obtains the Service Book's APN
// (Associated Access Point Name)
String sbAPN = _sRecordsArray[i].getAPN();
}
}
}
}

For a complete listing of available methods, please see the API reference included within the BlackBerry JDE 4.0. Additional information can be found in Chapter 10 of the BlackBerry Application Developer Guide Volume 2.

No comments:

Post a Comment

Place your comments here...