Hi, all.
Is there any way to show LOCAL html string in my BB application?
For example: I have a string
"<b>text-text-text</b> <A href="http://stackoverflow.com">link</A>"
How can I parse and show it as
text-text-text link?
Thanks.
Hi, all.
Is there any way to show LOCAL html string in my BB application?
For example: I have a string
"<b>text-text-text</b> <A href="http://stackoverflow.com">link</A>"
How can I parse and show it as
text-text-text link?
Thanks.
import javax.microedition.io.Connection; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; import java.util.; import java.io.;
import net.rim.blackberry.api.browser.Browser; import net.rim.blackberry.api.browser.BrowserSession; import net.rim.device.api.ui.; import net.rim.device.api.browser.field.; import net.rim.device.api.browser.plugin.BrowserPageContext; import net.rim.device.api.io.Base64OutputStream; import net.rim.device.api.io.http.HttpHeaders; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.system.Application; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.component.Status; import net.rim.device.api.ui.component.TextField;
final class bFieldExample extends UiApplication
{ private static final String REFERER = "referer";
public static final HttpConnection Utilities = null;
// private static final HttpConnection HttpConnection = null;
private RenderingSession rs;  
private MainScreen ms;
private HttpConnection  conn;
public static void main(String[] args)
{
    bFieldExample app = new bFieldExample();
    app.enterEventDispatcher();
 }
public bFieldExample()
{
    ms = new MainScreen();
    pushScreen(ms);
    rs = RenderingSession.getNewInstance();
    String s = <b>text-text-text</b> <A href="http://stackoverflow.com">link</A>
    //rs.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID,RenderingOptions.JAVASCRIPT_ENABLED, true);
    //LabelField l = new LabelField("Browser",LabelField.ELLIPSIS|LabelField.USE_ALL_WIDTH);
    ms.setTitle(new LabelField("Browser",LabelField.ELLIPSIS|LabelField.USE_ALL_WIDTH));        
    myThread thread = new myThread(s);
    thread.start();
}
class myThread extends Thread
{
    private String _url;
    myThread(String url)
    {
        _url=url;
    }
    public void run()
    {
        try {
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            Base64OutputStream boutput = new Base64OutputStream( output );                
            output.write( "data:text/html;base64,".getBytes() );
            boutput.write( _url.getBytes() );
            boutput.flush();
            boutput.close();
            output.flush();
            output.close();
            BrowserSession bSession = Browser.getDefaultSession();
            bSession.displayPage( output.toString() );
            } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
    }
}
}
You can use a BrowserField to render content in your application as a Field. In order to render HTML provided as a String rather than a URL, see this answer which involves mocking an HttpConnection.