Tag: browser

Invoke the browser with raw HTML

On the BrowserField2 (BlackBerry OS 5 and OS 6) the BrowserField has method to load the content from the String HTML raw.

this is the code for the previous version of BlackBerry OS, how to invoke the browser with the raw HTML.

The mechanism for using the BlackBerry Browser to invoke the browser with raw HTML content is shown in the sample code below. The key aspect of the code is the section where you pass in the following string to the browser at the start of the data sequence:

data:text/html;base64,

/*
* RawHTMLBrowserSample.java
*
* © Research In Motion Limited, 2007
* Confidential and proprietary.
*/

import java.io.*;
import javax.microedition.io.*;
import net.rim.blackberry.api.browser.*;
import net.rim.device.api.io.*;
import net.rim.device.api.system.*;
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.util.*;

/**
* A simple example of how to invoke the BlackBerry Browser using
* raw HTML data.
*/
public class RawHTMLBrowserSample extends UiApplication
{
    public static void main( String[] args )
    {
        RawHTMLBrowserSample sample = new RawHTMLBrowserSample();
        sample.enterEventDispatcher();
    }

    /**
    * Create the splash screen and start off the networking
    * thread that will eventually invoke the browser.
    */
    public RawHTMLBrowserSample()
    {
        MainScreen splashScreen = new MainScreen();
        splashScreen.add( new RichTextField( "Please Wait..." ));
        pushScreen( splashScreen );
        MyThread thread = new MyThread();
        thread.start();
    }
    private static class MyThread extends Thread
    {
        public void run()
        {
            try {
            // Open the connection and the input stream. Select your own URL.
            HttpConnection connection = (HttpConnection)Connector.open( "http://www.blackberry.com:80" );
            InputStream input = connection.openInputStream();
            DataBuffer buffer = new DataBuffer();
            byte[] temp = new byte[ 1024 ];
            // Read in the web page to the DataBuffer.
            for( ;; ) {
                int bytesRead = input.read( temp );
                if( bytesRead == -1 ) {
                    break;
                }
                buffer.write( temp, 0, bytesRead );
            }
            input.close();
            connection.close();
            // Create an output stream that will be used by the Base64 code.
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            Base64OutputStream boutput = new Base64OutputStream( output );
            // Write out the special sequence which indicates to the browser
            // that it should treat this as HTML data in base64 format.
            output.write( "data:text/html;base64,".getBytes() );
            boutput.write( buffer.getArray() );
            boutput.flush();
            boutput.close();
            output.flush();
            output.close(); // Invoke the browser with the encoded HTML content.
            BrowserSession bSession = Browser.getDefaultSession();
            bSession.displayPage( output.toString() );
        } catch( IOException e ) {
            System.out.println( "IOException: " + e );
        }
    }
}
}

The browser uses the sequence to base64 decode the string following the comma and displays it in the browser. When displaying the page, images and other items do not appear because the browser cannot fetch them.

This article applies to BlackBerry® Device Software 4.2 and later.

[1] http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/796557/800332/800440/How_To_-_Invoke_the_browser_with_raw_HTML.html?nodeid=1313878&vernum=0?CPID=EMC-DM2007M-37


BlackBerry User Agent (browser)

how to get blackberry user agent information like this:

Blackberry7290/4.1.0.139 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/-1

here is the answer[1]:

String userAgent = "Blackberry" + DeviceInfo.getDeviceName() + "/" + getOsVersion() + " Profile/" + System.getProperty( "microedition.profiles" ) + " Configuration/" + System.getProperty( "microedition.configuration" ) + " VendorID/" + Branding.getVendorId();
public static String getOsVersion()
{   String version = "";
    ApplicationDescriptor[] ad = ApplicationManager.getApplicationManager().getVisibleApplications();
    for( int i = 0; i < ad.length; i++)
    {   if( ad[i].getModuleName().trim().equalsIgnoreCase( "net_rim_bb_ribbon_app" ) )
        {   version = ad[i].getVersion();
            break;
        }
    }
    return version;
}

[1] http://www.blackberryforums.com/developer-forum/143972-profile-midp-2-0-configuration-cldc-1-1-how-get-info-programmatically.html



  • Copyright © 1996-2010 vaks.in. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress