0

Till now i was using SDK 5.0 and was able to dispaly local html text using net.rim.device.api.browser.field2.BrowserField but now my requirement has changed and have to use SDK 4.6. The problem is that now i'm getting compiler error for the BrowserField. Can anyone help me in displaying HTML text in SDK 4.6

Rahul Sharma
  • 3,637
  • 2
  • 20
  • 18

2 Answers2

3

As there is no BrowserField class supported in earlier versions of RIM SDK, you can launch local browser session for a html file, embedded in your cod-application.

Let say your application cod name is mymodule.cod

And you have attached a document.html file to your project, and this file is located in your source code folder, not outside.

You can launch browser session via this code:

    BrowserSession session = Browser.getDefaultSession();
    session.displayPage("cod://mymodule/document.html" ); 

Note, that module name is case sensitive.

And note that it is not documented way to access local html files.

If you are going to test this in simulator, make sure that MDS simulator is launched and is working.

1

It is still possible to display local HTML content with the APIs available for earlier BlackBerry OS versions. It is just a bit more complicated to make it work. Doing this involves the older BrowserField API (as opposed to the newer BrowserField2 API you've already discovered). I think the SDK includes a "BrowserField" example app that partially demonstrates this. It involves using the RenderingSession class to retrieve a BrowserContent object, which has a method to return a UI Field that you can actually show within your screen.

The trick is that RenderingSession expects you to supply it with an HttpConnection (or InputConnection) that it can read the data from. Since these are interfaces, you just have to implement them in such a way they they return your own HTML data instead of wrapping an actual HTTP connection.

It may be a little specific to the context of my own application, but here is an example of a class I wrote that wraps this API for local HTML content display: BrowserFieldRenderer

octo
  • 631
  • 3
  • 3