1

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.

Dean Brundage
  • 2,038
  • 18
  • 31

2 Answers2

1

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

Eric Giguere
  • 3,495
  • 15
  • 11
  • All I see there is "Invoking the BlackBerry Browser" which doesn't cover it. – Dean Brundage Feb 15 '11 at 22:39
  • If you want to invoke a link to an external site, the code is definitely on that page and in that section. Just click the link that says "Click here for a code sample that illustrates how to launch a BlackBerry Browser session from within a BlackBerry application." to expose the Java code you need. – Eric Giguere Feb 16 '11 at 01:03
  • Perhaps the question was not clear enough then. I already have a field2.BrowserField displaying HTML content that was packaged with my app. When the user clicks a link I want to launch the BlackBerry browser instead. – Dean Brundage Feb 16 '11 at 14:25
  • The code on that page does exactly that. Have you looked? You basically find the background process for the browser, set up some arguments, and then call runApplication to invoke it. – Eric Giguere Feb 16 '11 at 14:32
  • There is no way to catch the click event from a `BrowserField`, so I can't invoke the native browser once the `BrowserField` has displayed the local resource. – Dean Brundage Feb 16 '11 at 17:55
  • The title of your question is very misleading, then. But the answer is to override the handleNavigationRequest method as shown [here](http://supportforums.blackberry.com/t5/Java-Development/BrowserField2-handleNavigationRequest-os6/td-p/642543). – Eric Giguere Feb 16 '11 at 18:16
0

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;
}
Dean Brundage
  • 2,038
  • 18
  • 31