Search code examples
blackberry

Programmatically invoke browser in Blackberry


Need to show browser through my application. My application should go in background and browser should come in foreground.

int moduleHandle =
        CodeModuleManager.getModuleHandle("net_rim_bb_browser_daemon");
    if (moduleHandle > 0)
    {
        // Use the default browser application descriptor as the
        // model descriptor.
        ApplicationDescriptor[] browserDescriptors =
            CodeModuleManager.getApplicationDescriptors(moduleHandle);

        // Create the new application descriptor.
        String[] args = {"url", url, null};

        // Turn off auto restart (the original descriptor has it
        // turned on) so we don't end up in a never ending loop of
        // restarting the browser.
        int flags = browserDescriptors[0].getFlags() ^
             ApplicationDescriptor.FLAG_AUTO_RESTART;
        ApplicationDescriptor newDescriptor =
            new ApplicationDescriptor
            (
                browserDescriptors[0],
                "BrowserPS",
                 args,
                 null,
                 -1,
                 null,
                 -1,
                 flags
            );

        // Run the application.
        try
        {
            ApplicationManager.getApplicationManager().
                runApplication(newDescriptor);
        }
        catch (ApplicationManagerException ame)
        {
            System.err.println(ame.toString());
        }
    }

This is my code it's working fine in simulator, but not on actual device. any help.


Solution

  • Try like

      BrowserSession browserSession = Browser.getDefaultSession();
      browserSession.displayPage(URL);