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 Developer
rodrifox
Posts: 35
Registered: ‎12-22-2009
My Device: Bold 9700
Accepted Solution

Browser events on JDK 5 (field2 package)

Hello guys,

 

In the previous JDK (4.x) we had several classes to handle embedded browser events, like implementing the RenderingApplication interface, using the Event class, etc.; all of them part of the "net.rim.device.api.browser.field" package. But I can't find how to deal with embedded browser events with the new field2 package (as example, I need to capture the event triggered when the users clicks on a link in a BrowserField, something similar to Event.EVENT_URL_REQUESTED).

 

Any ideas? Thanks a lot.

 

 

 

-------------
Rodrigo Bravo
http://www.wilkonit.com
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Browser events on JDK 5 (field2 package)

Just fighting that battle myself.  Where is there a good demo of this Field?

 

Anyway, I think that the answer is that the links are directed to the

BrowserFieldController

specifically the

handleNavigationRequest

method.

 

I have created a BrowserField (bf), defined a myBrowserFieldController that just extends ProtocolController and passes these requests straight through, and then created a myBrowserFieldController using myBrowserFieldController(bf), which seems to associate the controller with the BrowserField.  having done that, clicks on links in the BrowserField end up in the handleNavigationRequest method as suggested.

 

Now a question for you and excuse me while I hijack your Thread!  Have you managed to get a BrowserField to display a picture.  I've pointed my BrowserField at the following, which is on my SDCard:

<html>
<body>

Test 2

<img src="test.png">
<br><br>
<a href="test.png">Picture</a>

</body>
</html>

 

Obviously test.png is there too.  Now I don't see test.png when I display this, but if I click on 'Picture', it will display it.  Why is the picture not showing when I display this html!

 

Any other helpful hints appreciated.....

New Developer
rodrifox
Posts: 35
Registered: ‎12-22-2009
My Device: Bold 9700

Re: Browser events on JDK 5 (field2 package)

Well that was other reason why I was looking to capture events: I can't show images on the browser like that. So what I've done (and this worked fine on JDK 4.x) is to include the img in the html like this:

 

<img src=myprotocol://some_location_on_my_bb>

 

after that, I was able to capture the event "net.rim.device.api.browser.field.Event.EVENT_URL_REQUESTED" (this event is captured when implementing RenderingApplication interface and implementing method "public Object eventOccurred(final Event event)") and then create my own HttpConnection that loaded the image using "Application.class.getResourceAsStream(...)". My event handler just override the URLs that start with "myprotocol" and pass through those that start with "http".

 

I will try now what you stated about the events in field2 and will let you know; if that works then this procedure should work also for you in order to show images and other stuff.

 

Thanks!

-------------
Rodrigo Bravo
http://www.wilkonit.com
New Developer
rodrifox
Posts: 35
Registered: ‎12-22-2009
My Device: Bold 9700

Re: Browser events on JDK 5 (field2 package)

I tried what Peter suggested and it worked like a charm. I was also able to load images as I told you, capturing the navigation request and loading from local storage when the protocol is not http.

What I've done is, first of all, construct the BrowserField:

 

    BrowserField field = new BrowserField();
    MyProtocolController myProtocolController = new MyProtocolController(field);
    field.getConfig().setProperty(BrowserFieldConfig.CONTROLLER, myProtocolController);
    field.displayContent(connection, ""); // connection is an HttpConnection instance

 

You need to implement MyProtocolController class of course, extending ProtocolController class and overriding method “public void handleNavigationRequest(BrowserFieldRequest arg0) throws Exception” so that you can handle the request properly. For example:

 

 

public void handleNavigationRequest(BrowserFieldRequest arg0) throws Exception {
if (arg0.startsWith("yourProtocol")) { // 1. Create HttpConnection and load resource from local storage like this: Base64OutputStream boutput = new Base64OutputStream(output); InputStream theResource = Application.class.getResourceAsStream(url-local-resource); byte[] resourceBytes = read(theResource); boutput.write(resourceBytes); boutput.flush(); boutput.close(); output.flush(); output.close(); String outString = output.toString(); Connection outputCon = Connector.open(outString); HttpConnection outputHttp = (HttpConnection) outputCon; // 2. Show content on browserfield browserField.displayContent(outputHttp, ""); } else { // Nothing to handle, so just pass through… super.handleNavigationRequest(arg0); }
}

 

You can handle resource requests (like images on <img> tags) in a similar way, but overriding method “public InputConnection handleResourceRequest(BrowserFieldRequest arg0) throws Exception”.

Hope this helps. Regards,

 

 

-------------
Rodrigo Bravo
http://www.wilkonit.com
Regular Contributor
ber4444
Posts: 67
Registered: ‎03-23-2010
My Device: all BB 7 (incl. prototypes)

Re: Browser events on JDK 5 (field2 package)

[ Edited ]
[deleted by author]
Developer
jromanoski
Posts: 90
Registered: ‎09-07-2010
My Device: Not Specified

Re: Browser events on JDK 5 (field2 package)

Hey,

 

I also tried what Peter suggested and it's working. Howeverm i'm trying to retrieve the images and css with the handleResourceRequest() method and i can't. I'm implementing it like this:

 

 

 

 

 

public InputConnection handleResourceRequest(BrowserFieldRequest request)
			throws Exception {
		System.out.println("RESOURCE REQUEST: " + request.getURL());
		return super.handleResourceRequest(request);
	}

 But not working. Any suggestions?