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

BrowserField Sample Code - Using the BrowserFieldConfig class

by Retired on ‎05-03-2010 04:47 PM - edited on ‎09-20-2010 09:49 AM by BlackBerry Development Advisor (18,427 Views)

This article applies to BlackBerry Device Software 5.0 and higher.

 

Default configuration settings are applied when you create an instance of the BrowserField class.  These configuration settings define the characteristics and behaviours of the web content that is rendered within a BrowserField object. 

 

You can override these default settings, altering the behaviour of your BrowserField, by using the BrowserFieldConfig class.

 

Some examples of characteristics that can be configured are:

 

  • Setting a custom User-Agent HTT header value
  • Changing the timeout value for JavaScript excution
  • Overriding the default cookie manager
  • etc.

 

Using the BrowserFieldConfig class in your application involves the following three steps:

 

  1. Create a BrowserFieldConfig object
  2. Call the setProperty method to override default configuration settings you wish to change
  3. Create a BrowserField object, using the BrowserFieldConfig object in the constructor

 

Here is an example of using the BrowserFieldConfig class in your application (See Creating your first BrowserField2 application for more info):

 

 

MyBrowserFieldConfig _config = new MyBrowserFieldConfig();
BrowserField _bf2 = new BrowserField(_config);

_screen = new MainScreen();
_screen.add(_bf2);
pushScreen(_screen);

_bf2.requestContent("http://devblog.blackberry.com");

 

This example uses a custom class named MyBrowserFieldConfig, that simply extends BrowserFieldConfig as a superclass.  Calls to setProperty are made within this class' constructor:

 

package samplecode;

import net.rim.device.api.browser.field2.BrowserFieldConfig;
import net.rim.device.api.system.ApplicationDescriptor;

/**
* @description - Demonstration of using BrowserFieldConfig class
* added to version 5.0 of the BlackBerry Device Software,
* @version 1.0
* @author Adam Stanley (astanley@rim.com), Developer Relations
* @category BlackBerry BrowserField Development: BrowserFieldConfig API
* @since April 30, 2010
* @see http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/browser/field2/BrowserFieldConfig.html
*/


/**
* The BrowserFieldConfig class provides a means to
* configure characteristics and behaviours of a BrowserField instance.
*/
public class MyBrowserFieldConfig extends BrowserFieldConfig
{
MyBrowserFieldConfig()
{
ApplicationDescriptor desc = ApplicationDescriptor.currentApplicationDescriptor();
if (desc != null)
{
String name = desc.getName();
String version = desc.getVersion();

//Default = BlackBerry Browser's User Agent
setProperty(BrowserFieldConfig.USER_AGENT, name + " " + version);
}


//The following settings can be configured:


//Default = FALSE
setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE);

//Default = FALSE
setProperty(BrowserFieldConfig.ENABLE_GEARS, Boolean.TRUE);

//Default = NAVIGATION_MODE_NONE
setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER);

//Default = 5000 milliseconds
setProperty(BrowserFieldConfig.JAVASCRIPT_TIMEOUT, new Integer(1000));

        //Default = Set by rendering engine
        setProperty(BrowserFieldConfig.HTTP_HEADERS, "Content-Type=text/html; CustomHeader=12345");    

        //Default = TRUE
        setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);    

        //Default = TRUE
        setProperty(BrowserFieldConfig.MDS_TRANSCODING_ENABLED, Boolean.FALSE);    
        //Default = TRUE:
        setProperty(BrowserFieldConfig.USER_SCALABLE, Boolean.FALSE);    

        //Default = None
        setProperty(BrowserFieldConfig.VIEWPORT_WIDTH, new Integer(app._screen.getWidth() / 2 ));
        
        //Default = None
        setProperty(BrowserFieldConfig.INITIAL_SCALE, new Float(1.5));

}
}

 

What to do next?

Check out the BrowserFieldListener class to add event handling to your application for certain browser events.

 

 

More

See the following learning resources for more information on the BrowserFieldConfig class:

 

Users Online
Currently online: 12 members 780 guests
Please welcome our newest community members: