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
New Member
happy8867
Posts: 2
Registered: ‎03-06-2013
My Device: I am a developer

How to open blackberry native browser from browse field app for external link?

I am working on an app for blackberry(jre 6.o & os 7.x) using browse field and app is working fine. One thing I want that, when click on a link in app and link url(domain) is different from the url which is invoked in app using browse field, open link in native blackberry browser. Please help me how to do this. Thanks.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to open blackberry native browser from browse field app for external link?

In your protocol controller (the class that extends ProtocolController and you use to supply content to the browserField) you can check in the

handleResourceRequest()

method for URLs you wish to send to the External Browser.  Then start it from there. 

 

However in this method you do have to supply content to the browserField.  So you can just create a simple html page saying "redirected to external Browser", and supply that. 

New Member
happy8867
Posts: 2
Registered: ‎03-06-2013
My Device: I am a developer

Re: How to open blackberry native browser from browse field app for external link?

can u please example code.I have tried this as u suggested but not able to achieve the target. Used code given here.Thanks.
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to open blackberry native browser from browse field app for external link?

I did this a while ago and am now not 100% that what I did was correct.  I am wondering if using handleNavigationRequest() is the more correct way to do it, but I don't think so.  My method works for me and it also appears that the proposed solution does not work for other people.

 

Basically using the code given in the link, you will see that handleResourceRequest() returns an InputConnection.  But before you return this data, you should check the requested URL,  If this URL is local to the device, then return the same as it currently does.

(InputConnection)Connector.open(request.getURL())

If the URL is not going to be supplied locally, then you just run the code that is currently in handleNavigationRequest()

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

This will start the Browser.  However you need to return an InputConnection from handleResourceRequest() - the BrowserField is expecting to display something.  So you can return this:

String pageData = "<html><body>Accessing external Content - see Browser<br /></body></html>
return new BrowserFieldResponse(resourceURI, pageData.getBytes(), HttpProtocolConstants.CONTENT_TYPE_TEXT_HTML);

Hopefully this will get you going