01-27-2010 11:00 AM
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.
Solved! Go to Solution.
01-27-2010 12:06 PM
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.....
01-27-2010 12:30 PM
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_
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!
01-28-2010 12:11 AM
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.C ONTROLLER, 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-re source);
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,
03-29-2010 11:48 AM - edited 03-30-2010 05:25 AM
11-06-2010 01:36 PM
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?