BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 10-06-2008, 09:41 AM   #1 (permalink)
New Member
 
Join Date: Sep 2008
Model: 8220
PIN: N/A
Carrier: n/a
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Trying to launch browser to specific URL with code, please help

Please Login to Remove!

Hi.

I'm trying to launch the browser to a specific URL when my application loads. When I try the following code the browser seems to open, but the progress bar constantly says 'Requesting', but the page never displays. If I leave it for long enough I do get some kind of, 'Cannot connect to the requested data source' message.

If I press the menu button an click 'Save Request' it does save the correct requested URL to a message. If I click on that message I get a dialog saying, 'The requested page is currently being loaded'.

I am running this code on a BlackBerry 8220 simulator.

Code:
/*
 * TestApp.java
 *
 *  <your company here>, 2003-2005
 * Confidential and proprietary.
 */

package sm;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.blackberry.api.browser.*;

/*
 * BlackBerry applications that provide a user interface
 * must extend UiApplication.
 */
public class TestApp extends UiApplication
{
        public static void main(String[] args)
        {
                //create a new instance of the application
                //and start the application on the event thread
                TestApp theApp = new TestApp();
                theApp.enterEventDispatcher();
        }

        public TestApp()
        {
                pushScreen(new TestAppScreen());

        }
}

final class TestAppScreen extends MainScreen
{
        public TestAppScreen()
        {
                //invoke the MainScreen constructor
                super();
                launchBrowser("xxx);

        }
        
        private static boolean launchBrowser(String url)
        {
            int handle = CodeModuleManager.getModuleHandle("net_rim_bb_browser_daemon");
            if(handle <= 0)
            {
                return false;
            }
            ApplicationDescriptor[] browserDescriptors = CodeModuleManager.getApplicationDescriptors(handle);
            if (browserDescriptors == null || browserDescriptors.length <= 0)
            {
                return false;
            }
            String[] args = {"url", url};
            ApplicationDescriptor descriptor = 
                new ApplicationDescriptor(
                    browserDescriptors[0],
                    "url invocation", args,
                    null,
                    -1,
                    null, 
                    -1,
                    ApplicationDescriptor.FLAG_SYSTEM
                );
            try 
            {
                ApplicationManager.getApplicationManager().runApplication(descriptor);
            }
            catch(ApplicationManagerException e) { return false; }
            return true;
        }           

        //override the onClose() method to display a dialog box to the user
        //with "Goodbye!" when the application is closed
        public boolean onClose()
        {
            Dialog.alert("Goodbye!");
            System.exit(0);
            return true;
        }
}
Obviously replace xxx with a url, but I cant post one on here.

I think it might have something to do with this all being done on the event thread. Do I need to use another thread somewhere along the line? If so, how might I go about doing this.

Any help would be much appriciated.

Regards,

Robin
Offline  
Old 10-06-2008, 10:01 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Instead of all your code you simply can do this :

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

it's works fine
Offline  
Old 10-06-2008, 10:41 AM   #3 (permalink)
New Member
 
Join Date: Sep 2008
Model: 8220
PIN: N/A
Carrier: n/a
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by goulamass View Post
Hi,

Instead of all your code you simply can do this :

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

it's works fine
That may work on some of the older phones, but will it work on the 8220? I don't think so because that sample code you gave is basically the same as the first code I tried, but does not work on newer phones because they don't allow you to start the browser with anything except a null string (or something like that).

Also will I need to get my RIM classes signed before this will work? Or does this only matter for an actual device, I am working on a simulator atm and hopped I would need to bother with singing untill my app worked.

Robin
Offline  
Old 10-06-2008, 12:25 PM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Sep 2008
Location: Romania
Model: 7130g
OS: v4.1.0.31
PIN: N/A
Carrier: Orange Romania
Posts: 57
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi everyone,

I would also appreciate some insight on this issue.
I am trying to add a feature to a small game, which allows people to open a page in their browser to submit their highscore online.
Offline  
Old 10-07-2008, 12:02 AM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2005
Model: 8900
Carrier: Cincinnati Bell
Posts: 30
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

That should work fine on any post 4.1 device.

I use this exact line in an app that I know works on 4.2,4.3 and 4.5

Code:
Browser.getDefaultSession().displayPage("http://www.google.com");
Offline  
Old 10-07-2008, 03:11 AM   #6 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

In fact you need to sign the code when you push the application on your mobile because the Browser Object is in a secured API.
Offline  
Old 10-07-2008, 03:31 AM   #7 (permalink)
New Member
 
Join Date: Sep 2008
Model: 8220
PIN: N/A
Carrier: n/a
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Regarding the siging of the app, is this required even when testing on a standalone RIM BlackBerry simulator?

I thought this might be an issue, but I expected to see some sort of an error telling me I need to sign my cod file, rather than the browser loading but just failing to connect to a website.

Thanks,

Robin
Offline  
Old 10-07-2008, 04:52 AM   #8 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

No if you are on the simulator you don't need to sign.

Is your MDS running when you try to connect???
Offline  
Old 10-07-2008, 08:23 AM   #9 (permalink)
New Member
 
Join Date: Sep 2008
Model: 8220
PIN: N/A
Carrier: n/a
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mds?
Offline  
Old 10-07-2008, 08:42 AM   #10 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hum do you know how a real blackberry works?

To resume, it connects to a MDS and this last connect him with the network and Internet.

So before launching your application you have to launch the MDS that you found on the menu start => All the programs => Research In Motion => BlackBerry JDE... => MDS.

This allows your simulator to connect with the web.
Offline  
Old 10-07-2008, 08:42 AM   #11 (permalink)
Thumbs Must Hurt
 
Join Date: Sep 2008
Location: Romania
Model: 7130g
OS: v4.1.0.31
PIN: N/A
Carrier: Orange Romania
Posts: 57
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is some code I used in JDE 4.1
It does open the browser but not the url ... it stucks at : "Requesting..."

Code:
   public void VisitHomePage()
   {
       
boolean retval = true;

int handle = CodeModuleManager.getModuleHandle("net_rim_bb_browser_daemon");

if (handle <=0 ) {
     retval = false;
}
else {
     ApplicationDescriptor[] browserDescriptors = CodeModuleManager.getApplicationDescriptors(handle);

     if (browserDescriptors == null ) {
          retval = false;
     }
     else
     {
          if ( browserDescriptors.length <=0 ) {
               retval = false;
          } else {
               String[] args = {"url", "http://mobile.exosyphen.com"};

               ApplicationDescriptor descriptor = new ApplicationDescriptor
               (
                    browserDescriptors[0],
                    "url invocation", args,
                    null, -1, null, -1,
                    ApplicationDescriptor.FLAG_SYSTEM
               );

               try
               {
                    ApplicationManager.getApplicationManager().runApplication(descriptor);
               }
               catch(ApplicationManagerException e)
               {
                    retval = false;
               }
          }
     }
}

       
       
   }
Offline  
Old 10-07-2008, 08:45 AM   #12 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

As I say before check if your mds is running
Offline  
Old 10-08-2008, 03:34 AM   #13 (permalink)
New Member
 
Join Date: Sep 2008
Model: 8220
PIN: N/A
Carrier: n/a
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Thank You!

Goulamass,

I found the MDS program which you mentioned and having that running solved all of my problems.

I do aplogise for being such a noob, but I usually just develop websites in PHP.

Thanks for the help.

Robin
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.