load html on Blackberry4.6 os version

时光总嘲笑我的痴心妄想 提交于 2019-12-20 06:11:53

问题


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:


You can show your html document in this way

BrowserSession session = Browser.getDefaultSession();
session.displayPage("cod://Name of your application code file/test.html");



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/9991482/load-html-on-blackberry4-6-os-version

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!