在Blackberry4.6操作系统版本上加载html

时间:2012-04-03 10:33:24

标签: java blackberry

您好我是黑莓应用程序开发的新手我想在浏览器字段中加载HTML .. 我能够为版本5和6以及更多版本加载HTML,但它不会在OS版本4中加载

请告诉我如何使用Eclipsed在Blackberry OS版本4.6上加载此HTML 开发应用程序5和6工作正常,但在4.6不plz告诉我如何写。代码中的此代码或任何特定更改的代码,或者我们无法在OS 4.6版中加载HTML?

BrowserField mybroBrowserField=new BrowserField();

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

此代码适用于5个且超过5个版本但不适用于OS版本4

3 个答案:

答案 0 :(得分:2)

您可以用这种方式显示您的HTML文档

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

答案 1 :(得分:0)

BrowserField仅在BlackBerry API 5.0.0之后存在,但您可以使用LogicMail中的此自定义BrowserFieldRenderer class来解决您的问题

答案 2 :(得分:0)

如果您使用BlackBerry Eclipse Plug-in开发BB应用程序,则可以导入示例BlackBerry项目。在列表中有类似BlackBerry Browser Field Demo的内容。只需导入它并了解其工作原理。
将此代码段插入“实用工具”类

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());
        }
    };
}


并调用此方法而不是makeConnection(String url, HttpHeaders requestHeaders, byte[] postData)方法。