Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Supplying own content to BrowserField2

I'm trying to supply my own content to a BrowserField2.  By my own content, I mean, I supply the html from my program.  So, say a request was made for page aaaa.html, then I could supply "<html><body>This is page aaa</body></html>. 


I'm using an approach that, according to my reading of the API, should allow this.  However it is not working. 


The approach I'm using involves establishing my own protocol, and then processing this. 


BrowserField2 allows you to specify the ProtocolController and this Object allows you specify handlers that will assist with navigation and supply resources.  You can associate a protocol with these handlers. 


So I have created my own ProtocolController, created an object that handles both navigation and resource requests and told the ProtocolController to use my handler.  I then told the BrowserFieldConfiguration to use my ProtocolController.  And then I try to display a page, using my protocol.


It all looks like it works.  But the request to get the page never happens.  The request to navigate to it does.  I see the output from this line:

System.out.println("BrowserFieldRequesthandler - handleNavigationRequest: " + request.getURL());

but I never see anything form this:

System.out.println("BrowserFieldRequesthandler - handleNavigationRequest: " + resourceURI);


The BrowserField displays but is blank.


Anyone any idea what I'm doing wrong?


Code that I'm using is pasted below. 


class MyBrowserField2Sample extends UiApplication {    
    private MainScreen _screen;
    private BrowserField _bf2;
    private ProtocolController _myProtocolController;
    private BrowserFieldConfig _myBrowserFieldConfig;
    private BrowserFieldRequestHandler _browserRequestHandler;

    MyBrowserField2Sample() {
        _browserRequestHandler = new BrowserFieldRequestHandler();
        _myBrowserFieldConfig = new BrowserFieldConfig();
        _bf2 = new BrowserField(_myBrowserFieldConfig);
        _myProtocolController = new ProtocolController(_bf2);
        _myBrowserFieldConfig.setProperty(BrowserFieldConfig.CONTROLLER, _myProtocolController);
        String myProtocol = "test";
        _myProtocolController.setNavigationRequestHandler(myProtocol, _browserRequestHandler);
        _myProtocolController.setResourceRequestHandler(myProtocol, _browserRequestHandler);
        _screen = new MainScreen();
        String addressToDisplay = "test://www.rim.com/index.html";

    public static void main(String[] args) {
        MyBrowserField2Sample app = new MyBrowserField2Sample();        


public class BrowserFieldRequestHandler extends Object
                                        implements BrowserFieldResourceRequestHandler, BrowserFieldNavigationRequestHandler {

    public void handleNavigation(BrowserFieldRequest request) throws Exception {
        System.out.println("BrowserFieldRequesthandler - handleNavigationRequest: " + request.getURL());

    public InputConnection handleResource(BrowserFieldRequest request) throws Exception {
        String resourceURI = request.getURL();
        System.out.println("BrowserFieldRequesthandler - handleNavigationRequest: " + resourceURI);
        String contentMessage = "Requested content: " + resourceURI;
        String webData = "<html><body>" + contentMessage + "</body></html>";
        return new BrowserFieldResponse(resourceURI, webData.getBytes(), HttpProtocolConstants.CONTENT_TYPE_TEXT_HTML);



Please use plain text.
Posts: 13
Registered: ‎06-18-2009
My Device: Not Specified

Re: Supplying own content to BrowserField2



If you want to just supply the static content to bf2 then there is an easy option available by invoking the

api bf2.requestContent("local:///mysample.html")


hope this helps.

Please use plain text.