Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
hmtan02
Posts: 17
Registered: ‎08-01-2010
My Device: BlackBerry Bold 9700

Display Webpage

Hi

 

I am trying to launch the browser when clicking on a button but it doesn't seem to respond. My code is as follows:

 

    public UKNewsMainScreen(){
        
        super();
        
        LabelField title = new LabelField("UK Daily Newspapers",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
        setTitle(title);
        
        
        HorizontalFieldManager backGround = new HorizontalFieldManager();
        VerticalFieldManager _left = new VerticalFieldManager();
        VerticalFieldManager _middle = new VerticalFieldManager();
        VerticalFieldManager _right = new VerticalFieldManager();
    
        
        _theSun = Bitmap.getBitmapResource("The_Sun.png");
        _bitmap = new BitmapField();
        _bitmap.setBitmap(_theSun);
        _left.add(_bitmap);
        
        _papername = new LabelField ("The Sun UK");
        _middle.add(_papername);
    
            
        theSun = new ButtonField ("Launch",ButtonField.CONSUME_CLICK);
        theSun.setChangeListener(this);
        _right.add(theSun);
        

        
        
        _EN = Bitmap.getBitmapResource("Edinburgh_News.png");
        _bitmap = new BitmapField();
        _bitmap.setBitmap(_EN);
        _left.add(_bitmap);
        
         _papername = new LabelField ("Edinburgh Evening News");
        _middle.add(_papername);
        
                    
         _EN1 = new ButtonField ("Launch",ButtonField.CONSUME_CLICK);
         _EN1.setChangeListener(this);
        _right.add(_EN1);
        
        backGround.add(_left);
        backGround.add(_middle);
        backGround.add(_right);
        
        
        add(backGround);
        
    }


    public void fieldChanged(Field field, int context) {
        if ( field == theSun ) {
            browserSession = Browser.getDefaultSession();
            browserSession.displayPage("http://www.BlackBerry.com");
                    }
        if ( field == _EN1 ) {
            browserSession = Browser.getDefaultSession();
            browserSession.displayPage("http://www.google.com");
                    
    }
    }
    }

 

 

I have read that you can also use BrowserField2 which is more advance. Any ideas on how to use it from a button?

 

thanks

Please use plain text.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Display Webpage

If u r using JDE 5.0,

 Then U can use BrowserField Class.

----------------------------------------------------

Press Kudoed If Got Solution.

Please use plain text.
Contributor
hmtan02
Posts: 17
Registered: ‎08-01-2010
My Device: BlackBerry Bold 9700

Re: Display Webpage

Sorry should have included my JDE earlier. yes I am using 5.0

 

Any idea how to invoke it through a button?

Please use plain text.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Display Webpage

This is the Sample code for BrowserField

 

 

class Mainfile extends MainScreen implements FieldChangeListener
{
    MainScreen screen;
    BrowserField field;
    TextField text;
    ButtonField go;
    String str=null;

    public Mainfile() 
    {
        LabelField label=new LabelField("Enter the URL :",LabelField.ELLIPSIS|LabelField.USE_ALL_WIDTH);
        add(label);
        //label.setMargin(10,10,10,10);
        //label.setPadding(10,10,10,10);
        text=new TextField();
        add(text);
        text.setText("http://");
        go=new ButtonField("GO");
        go.setChangeListener(this);
        add(go);
        field=new BrowserField();
        screen=new MainScreen();
        screen.add(field);        
    }

    public void fieldChanged(Field f,int C)
    {
        if(f==go)
        {
            //String str=text.getText();
	    String str="rtsp://qt2.netro.ca/princess_54.3gp";
            field.requestContent(str);
            if(str.equals("http://"))
                {
                    Dialog.alert("Plz Enter the URL");
                }
            else
            {
                UiApplication.getUiApplication().pushScreen(screen);
            }
        }
    }
}

 

 

--------------------------------------------------------------------------------------------------------------------------------------

Press Kudoed If got Answer.

Please use plain text.
Contributor
morpheusghost
Posts: 34
Registered: ‎07-30-2010
My Device: Not Specified

Re: Display Webpage

[ Edited ]

try this method:

 

private void invokeBrowser(String uri) {
        BrowserSession browserSession = Browser.getDefaultSession();
        browserSession.displayPage(uri);
    }

 

Edit: oups!!! sorry i just saw that you already use it

Please use plain text.
Developer
QuiteSimple
Posts: 1,452
Registered: ‎11-06-2009
My Device: Torch 9810

Re: Display Webpage

Are you sure that the browser didn't load the content of the URL?

 

I have observed such behaviour:

 

1) Trying to start the browser with the same code you have

2) The browser is not starting

3) WTF???

4) Switch application - select Browser

5) the url is loaded in the browser

 

Bottom line: browser is not pushed in foreground but the content is loaded.



"When you become a level 3 developer, you learn to communicate over the ether. I'm told that level 5 developers are ascend into a higher level of existence beyond the physical realm." gord888 @ crackberry
Please use plain text.
Contributor
hmtan02
Posts: 17
Registered: ‎08-01-2010
My Device: BlackBerry Bold 9700

Re: Display Webpage

tried the modofiy my code using the example but i am getting the error below when i click on the button

2826i3A6A46475FF77FDB

 

 

here is my code:

 

public class UKNewsMainScreen extends MainScreen implements FieldChangeListener {
    
    
    private Bitmap _EN;
    private Bitmap _theSun;
    private BitmapField _bitmap;
    private LabelField _papername;
    private ButtonField theSun;
    private ButtonField _EN1;
    private Manager backGround;
    private BrowserSession browserSession;
    private BrowserField field;
    private MainScreen screen;
    private String str = null;



public UKNewsMainScreen(){
        
        super();
        
        LabelField title = new LabelField("UK Daily Newspapers",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
        setTitle(title);
        
        
        HorizontalFieldManager backGround = new HorizontalFieldManager();
        VerticalFieldManager _left = new VerticalFieldManager();
        VerticalFieldManager _middle = new VerticalFieldManager();
        VerticalFieldManager _right = new VerticalFieldManager();
    
        
        _theSun = Bitmap.getBitmapResource("The_Sun.png");
        _bitmap = new BitmapField();
        _bitmap.setBitmap(_theSun);
        _left.add(_bitmap);
        
        _papername = new LabelField ("The Sun UK");
        _middle.add(_papername);
    
            
        theSun = new ButtonField ("Launch",ButtonField.CONSUME_CLICK);
        theSun.setChangeListener(this);
        _right.add(theSun);
        
           
     
        _EN = Bitmap.getBitmapResource("Edinburgh_News.png");
        _bitmap = new BitmapField();
        _bitmap.setBitmap(_EN);
        _left.add(_bitmap);
        
         _papername = new LabelField ("Edinburgh Evening News");
        _middle.add(_papername);
        
                    
         _EN1 = new ButtonField ("Launch",ButtonField.CONSUME_CLICK);
         _EN1.setChangeListener(this);
        _right.add(_EN1);
        
         backGround.add(_left);
         backGround.add(_middle);
         backGround.add(_right);
         add(backGround);

    field = new BrowserField();
    screen = new MainScreen();
    screen.add(field);
        
    }
public void fieldChanged(Field f,int C)
    {
        if(f==theSun)
        {
        String str="www.thesun.co.uk";
            field.requestContent(str);
                        }
        else
        {
            UiApplication.getUiApplication().pushScreen(screen);
        }
    }
}

 

Need Help Please!

 

thanks

Please use plain text.
Contributor
hmtan02
Posts: 17
Registered: ‎08-01-2010
My Device: BlackBerry Bold 9700

Re: Display Webpage

tried this as well.

nope the content is not loaded on the browser

Please use plain text.