Welcome!

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

Reply
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT
Accepted Solution

BrowserField - open links in actual browser?

Hey guys, wondering if any one can help me out or give a little guidance on this issue.

 

I have a local html string that I am displaying on a screen inside of a BrowserField object, and what I want to do is have any link inside the field that is clicked to open the link inside of an actual browser session. I looked through the API for an method to override that handles the links but didnt see one, although I could have just missed it. Any suggestions?

 

Thanks

Kyle

Like all of my posts
Please use plain text.
Developer
hades_6
Posts: 178
Registered: ‎08-26-2009
My Device: Not Specified

Re: BrowserField - open links in actual browser?

Looking for something similar, has anyone done this? or even override the navigation click?

Please use plain text.
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: BrowserField - open links in actual browser?

Alright, so in the 5.0 API there is a method getController() in the BrowserField class that returns a BrowserFieldController object, which subsequently has a handleNavigationRequest which is what I would assume you would want to use if you wanted to intercept the link press. Does anyone know how to override this and apply it to the browser field? There is no set method for the controller so I havent found a way.

Like all of my posts
Please use plain text.
Developer
hades_6
Posts: 178
Registered: ‎08-26-2009
My Device: Not Specified

Re: BrowserField - open links in actual browser?

There was a nice implementation by someone, can't remember though. If you search the forums you can find it. It works in the API's below 5.0 :smileyhappy:

Please use plain text.
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: BrowserField - open links in actual browser?

Hey Guys,

 

I know this thread has been dormant for a while but I found the solution so I thought id post her if anyone else ever has the same issue.

 

 

BrowserFieldConfig bfc = new BrowserFieldConfig();
bfc.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_CARET);
bfc.setProperty(BrowserFieldConfig.CONTROLLER, new BrowserFieldController(){
			
			public InputConnection handleResourceRequest(BrowserFieldRequest request)
					throws Exception {
				
				return (InputConnection)Connector.open(request.getURL());
			}
			
			public void handleNavigationRequest(BrowserFieldRequest request)
					throws Exception {
				BrowserSession b = Browser.getDefaultSession();
				b.displayPage(request.getURL());
			}
		});
		bf = new BrowserField(bfc);

 

 

Like all of my posts
Please use plain text.
Developer
n8r0n
Posts: 40
Registered: ‎03-29-2009
My Device: Storm 9550
My Carrier: AT&T

Re: BrowserField - open links in actual browser?

[ Edited ]

I tried the code above, but what I got was that all content was opened in the full-fledged browser.  I was wanting to display local HTML content in my BrowserField, and if the user followed links from inside that content, to external HTTP sites, then I wanted to spawn the browser.  Here's how I acheived that, instead of the code above.

 

      BrowserFieldConfig fieldConfig = new BrowserFieldConfig();
      fieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER);
      _browserField = new BrowserField(fieldConfig);
      
      // Use the default (full-featured) browser to view external http content
      ProtocolController hybridController = new ProtocolController(_browserField);      
      hybridController.setNavigationRequestHandler("http", 
              new BrowserFieldNavigationRequestHandler() {                 
                 public void handleNavigation(BrowserFieldRequest request) {                    
                    BrowserSession browser = Browser.getDefaultSession();
                    browser.displayPage(request.getURL());                   
                 }
              });
      _browserField.getConfig().setProperty(BrowserFieldConfig.CONTROLLER, hybridController);

      add(_browserField);

  

Of course, if you also want HTTPS content handled this way, I'm guessing you need to add another call to setNavigationRequestHandler, for "https".  But, you get the idea.

Please use plain text.
Developer
Astarot82
Posts: 53
Registered: ‎10-29-2010
My Device: Not Specified

Re: BrowserField - open links in actual browser?

It's easy n8r0n:

 

Instead of:

BrowserSession browser = Browser.getDefaultSession();
browser.displayPage(request.getURL());

 

use:

 

 

_browserField.requestContent(request);

 

 

Please use plain text.
Developer
n8r0n
Posts: 40
Registered: ‎03-29-2009
My Device: Storm 9550
My Carrier: AT&T

Re: BrowserField - open links in actual browser?

Please read the original question.  He (and I) didn't want to open up content inside of the BrowserField itself.  We wanted to spawn the external Browser to open content when links are clicked.

 

Your code does not do that.

Please use plain text.