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
Regular Contributor
Posts: 82
Registered: ‎10-28-2010
My Device: Not Specified

Populating a BrowserField within a Popup Screen from a local html file - How to Do ?

 

I am trying to populate a

net.rim.device.api.browser.field2.BrowserField;

 with some html stored in a file.

 

I've managed to load the file in to a string object (via the ' this.getClass().getResourceAsStream ' )

 

but it seem the when i plant the string in to the command

 

browserField.displayContent(htmlString, "http://localhost");

 if throwns an error on the device.

 

There must be a simple way of displaying HTML ... Am i using the wrong method or field.

 

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Populating a BrowserField within a Popup Screen from a local html file - How to Do ?

blackberry does not have localhost or 127.0.0.1

you can use the cod:// protocol to access a local file, for example:
String localUrl = "cod://ModuleName/license_eng.htm";
BrowserSession browserSess = Browser.getDefaultSession();
browserSess.displayPage(localUrl);
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 82
Registered: ‎10-28-2010
My Device: Not Specified

Re: Populating a BrowserField within a Popup Screen from a local html file - How to Do ?

I am working within a Popup screen not the browser... so i don't have a session. it needs to be displayed within a screen.
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Populating a BrowserField within a Popup Screen from a local html file - How to Do ?

try this:
browserField.displayContent(htmlString, "");

if you have problems with the encoding you can ask for more.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 82
Registered: ‎10-28-2010
My Device: Not Specified

Re: Populating a BrowserField within a Popup Screen from a local html file - How to Do ?

That doesn't work

Error message:
Error displaying content for:

Error message: ApplicationRegistry.waitFor(0xd0 ...)
timeout
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Populating a BrowserField within a Popup Screen from a local html file - How to Do ?

full code?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 82
Registered: ‎10-28-2010
My Device: Not Specified

Re: Populating a BrowserField within a Popup Screen from a local html file - How to Do ?

as requested

 

public class EulaPopup extends PopupScreen {

	
	public EulaPopup() {
		super(new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR));

		this._accept = accept;
		this._decline = decline;
		LabelField title = new LabelField("EULA");
		title.setFont(title.getFont().derive(Font.UNDERLINED | Font.BOLD));
		add(title);

		BrowserField eulaText = new BrowserField();
		InputStream is = this.getClass().getResourceAsStream("EULA.HTML");
		
		

		final char[] buffer = new char[0x10000];
		StringBuffer out = new StringBuffer();
		
		try {
			Reader in = new InputStreamReader(is, "UTF-8");
			int read;
			do {
				read = in.read(buffer, 0, buffer.length);
				if (read > 0) {
					out.append(buffer, 0, read);
				}
			} while (read >= 0);
		} catch (Exception e) {
			//something went wrong
		}
		final String eulaContent = out.toString();
		add(eulaText);
		
		eulaText.displayContent(eulaContent, "");

		

		ButtonField acceptButton = new ButtonField("Accept",
				ButtonField.CONSUME_CLICK | Field.FIELD_HCENTER);
		acceptButton.setChangeListener(new FieldChangeListener() {
			public void fieldChanged(Field field, int context) {
				
				close();
			}
		});
		add(acceptButton);
		
		
	}

}

 

any suggestion ?