2011-10-18 98 views
1

需要通过我的应用程序显示浏览器。 我的应用程序应该放在后台,浏览器应该在前台。以编程方式调用浏览器

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()); 
     } 
    } 

这是我的代码它的正常工作在模拟器,而不是实际的设备上。 任何帮助。

+2

你在'net.rim.blackberry.api.browser.Browser'和'net.rim.blackberry.api.browser.BrowserSession'类看了没有? –

回答

1

尝试像

BrowserSession browserSession = Browser.getDefaultSession(); 
    browserSession.displayPage(URL); 
相关问题