I am trying to create a screen for a blackberry 5.0+ app that has a banner at the top and then a Browserfield
underneath that views an external site. The banner is hosted on one site and the content for the BrowserField
is hosted on another.
Originally I tried using 2 BrowserFields but had issues when several devices did not display the banner and only showed the content underneath. Furthermore when another screen with the same setup was displayed the app would crash with an IllegalStateException
. I did a bit of research and it seems that BrowserField
seems to have some trouble when several instances of it exist at once.
So in order to get around this issue I have combined both BrowserField
s into one, using the frame tag in html, with the hopes of displaying the Banner ad in the first frame and the content underneath in the second frame.
The html I made works in a normal browser:
<!DOCTYPE html>
<html>
<frameset rows="10%,90%">
<frame scrolling="no" src="http://4.bp.blogspot.com/_CZ1HhhanNgc/TI0xscVLW8I/AAAAAAAABps/sfeO4E3234k/s1600/head-mp-700x88.jpg" noresize="noresize" frameborder="0">
<frame src="http://www.penny-arcade.com" frameborder="0">
</frameset>
</html>
What I am doing is reading the html in as text, removing the \n
and \r
s and then putting it in the following method: browserField.displayContent(html,"http://localhost");
This method is supposed to display the html in the browser, but instead on the simulator I get this:
On the device I get a blank screen. I don't know whats going on with the displayContent()
method, so I would assume that it doesn't allow external sites? I don't really know what my options are from this point on. Is there some kind of fix for this, some library that I can use or some other way to implement this?
Edit:
So @Nate suggested a change to the DOCTYPE
tag, and posted a screenshot of the html working. However I did this and I still get the same results, so I am going to post the code I'm using to make the screen. Here it is:
public final class MyScreen extends MainScreen
{
/**
* Creates a new MyScreen object
*/
private BrowserField browserField;
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle");
BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.VIEWPORT_WIDTH, new Integer(Display.getWidth()));
config.setProperty(BrowserFieldConfig.NAVIGATION_MODE,
BrowserFieldConfig.NAVIGATION_MODE_POINTER);
config.setProperty(BrowserFieldConfig.INITIAL_SCALE, new Float(1.0));
config.setProperty(BrowserFieldConfig.USER_SCALABLE, Boolean.FALSE);
//supposed to prevent InvalidStateException from refreshing sometimes
ProtocolController eventsProtocolController = new ProtocolController(browserField)
{
public void handleNavigationRequest(BrowserFieldRequest request) throws Exception
{
browserField.setFocus();
super.handleNavigationRequest(request);
}
};
config.setProperty(BrowserFieldConfig.CONTROLLER, eventsProtocolController);
browserField = new BrowserField(config);
try
{
String embeddedLinkFrame = readTextFile("frame.html");
browserField.displayContent(embeddedLinkFrame, "http://localhost");
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
add(browserField);
}
public String readTextFile(String fName)
{
String result = null;
DataInputStream is = null;
try
{
is = new DataInputStream(getClass().getResourceAsStream("/" + fName));
byte[] data = IOUtilities.streamToBytes(is);
result = new String(data);
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
finally
{
try
{
if (null != is)
is.close();
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
return result;
}
}