Blackberry: Launch native browser from embeded browser

1.1k views Asked by At

I am writing an JRE 5.0.0 app. The app has some HTML tips content that I display with a field2.BrowserField. I'd like to launch the native browser when a user clicks certain links. I've read the docs for BrowserFieldListener, but that doesn't look like the solution.

[Edit]

Alternatively: invoke native browser with a local document. EG:

BrowserSession session = Browser.getDefaultSession();
session.displayPage("file:///Blark/");

[/Edit]

Thanks.

2

There are 2 answers

0
Dean Brundage On BEST ANSWER

I decided to launch the system browser and feed it the local file.

public boolean launchBrowserWithLocalResource(String resource)
{
    boolean answer = false;

    InputStream input = AppLauncher.class.getResourceAsStream(resource);

    if( input != null )
    {
        DataBuffer buffer = new DataBuffer();
        ByteArrayOutputStream output = null;

        try
        {
            byte[] temp = new byte[input.available()];

            while(true)
            {
                int bytesRead = input.read(temp);

                if( bytesRead == -1 )
                    break;

                buffer.write( temp, 0, bytesRead );
            }
            input.close();

            output = new ByteArrayOutputStream();

            Base64OutputStream boutput = new Base64OutputStream(output);

            output.write( "data:text/html;base64,".getBytes() );
            boutput.write( buffer.getArray() );

            boutput.flush();
            boutput.close();

            output.flush();
            output.close();

        } catch( IOException e )
        {
            Logger.log( "Caught IOException: " + e.getMessage() );
        }

        if( output != null )
        {
            BrowserSession bSession = Browser.getDefaultSession();
            bSession.displayPage( output.toString() );
            answer = true;
        }

    } else
    {
        Logger.log( "File not found: " + resource );
    }
    return answer;
}
6
Eric Giguere On

RIM's app integration summary provides some sample code to do this. It's obscure, but it works.