开发者

Blackberry: Launch native browser from embeded browser

开发者 https://www.devze.com 2023-02-11 10:29 出处:网络
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 t开发者_如何转开发he native browser when a user clicks certain links.I\'v

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 t开发者_如何转开发he 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.


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


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消