load html on Blackberry4.6 os version

2019-03-05 06:57发布

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

3条回答
We Are One
2楼-- · 2019-03-05 07:17

You can show your html document in this way

BrowserSession session = Browser.getDefaultSession();
session.displayPage("cod://Name of your application code file/test.html");
查看更多
Juvenile、少年°
3楼-- · 2019-03-05 07:25

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.

查看更多
做个烂人
4楼-- · 2019-03-05 07:26

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

查看更多
登录 后发表回答