0

Hi I'm new in Blackberry app development i want to load HTML in browser field.. I'm able to load HTML for version 5 ,and 6 and more but it not loading in OS version 4

plz tell me how to load this HTML on Blackberry OS version4.6 i m using Eclipsed to developing application on 5 and 6 works properly but in 4.6 not plz tell me how to write. Code for this or any specific change in code or we cant load HTML in OS version 4.6?

BrowserField mybroBrowserField=new BrowserField();

add(mybroBrowserField);
mybroBrowserField.displayContent(
"<html><body><h1>hello world! This blackbery apps</h1>   </body></html>",  
"http://localhost");

this code apply for 5 and more than 5 version but not work for OS version 4

1
  • Please don't repost questions. Commented Apr 4, 2012 at 9:29

3 Answers 3

2

You can show your html document in this way

BrowserSession session = Browser.getDefaultSession();
session.displayPage("cod://Name of your application code file/test.html");
6
  • i have try this also but not working .just tell me how to load Html in Browser filed . in Os Version 4.6 Commented Apr 4, 2012 at 5:20
  • It work fine for me and BrowerSession is available from 4.0. If you can post your code what exactly you are doing then I will able to solve the problem
    – Nsr
    Commented Apr 4, 2012 at 5:22
  • code is Upper i just want to Hello world which is in HTML format just see and plz tell me revised code . this code is work for 5 and more than 5 version but when i run this code on 4.6 its not working. Commented Apr 4, 2012 at 5:29
  • BrowserField mybroBrowserField=new BrowserField(); add(mybroBrowserField); mybroBrowserField.displayContent( "<html><body><h1>hello world! This blackbery apps</h1> </body></html>", "localhost"); Commented Apr 4, 2012 at 5:29
  • In my code you have to give the name of html file which are located in your project resources........ So for that one way is to do that is you can make a .html file for your data and copy it in your project resource and specify the name of that html file
    – Nsr
    Commented Apr 4, 2012 at 5:32
0

If you are using BlackBerry Eclipse Plug-in to develop BB apps, you can import sample BlackBerry projects. In the list there is something like BlackBerry Browser Field Demo. Just import that and find out how this works.
Insert this snippet to Utilities class

private static DataInputStream dataInput;
private static InputStream in;
static HttpConnection makeDummyConnection(String htmlData){
    try {
        in = new ByteArrayInputStream(htmlData.getBytes("UTF-8"));
        dataInput = new DataInputStream(in);
    } catch (Exception e) {
        System.out.println("HttpConnectionImpl : Exception : " + e);
    }
    return new HttpConnection() {
         public String getURL() {
            return "";
        }

        public String getProtocol() {
            return "";
        }

        public String getHost() {
            return "";
        }

        public String getFile() {
            return "";
        }

        public String getRef() {
            return "";
        }

        public String getQuery() {
            return "";
        }

        public int getPort() {
            return 0;
        }

        public String getRequestMethod() {
            return "";
        }

        public void setRequestMethod(String s) throws IOException {

        }

        public String getRequestProperty(String s) {
            return "";
        }

        public void setRequestProperty(String s, String s1) throws IOException {

        }

        public int getResponseCode() throws IOException {
            return 200;
        }

        public String getResponseMessage() throws IOException {
            return "";
        }

        public long getExpiration() throws IOException {
            return 0;
        }

        public long getDate() throws IOException {
            return 0;
        }

        public long getLastModified() throws IOException {
            return 0;
        }

        public String getHeaderField(String s) throws IOException {
            return "";
        }

        public int getHeaderFieldInt(String s, int i) throws IOException {
            return 0;
        }

        public long getHeaderFieldDate(String s, long l) throws IOException {
            return 0;
        }

        public String getHeaderField(int i) throws IOException {
            return "";
        }

        public String getHeaderFieldKey(int i) throws IOException {
            return "";
        }

        public String getType() {
            return "text/html";
        }

        public String getEncoding() {
            return "text/html";
        }

        public long getLength() {
            return 7000;
        }

        public InputStream openInputStream() throws IOException {
            return in;
        }

        public DataInputStream openDataInputStream() throws IOException {
            return dataInput;
        }

        public void close() throws IOException {

        }

        public OutputStream openOutputStream() throws IOException {
            return new ByteArrayOutputStream();
        }

        public DataOutputStream openDataOutputStream() throws IOException {
            return new DataOutputStream(new ByteArrayOutputStream());
        }
    };
}


and call this instead of makeConnection(String url, HttpHeaders requestHeaders, byte[] postData) method.

0

BrowserField exist only since BlackBerry API 5.0.0, but you can use this custom BrowserFieldRenderer class from LogicMail to solve your problem

1
  • how we will put this class can tell me because i have try this not able to do .. Commented Apr 4, 2012 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.