代码之家  ›  专栏  ›  技术社区  ›  Dan J Akhil

在本机BlackBerry应用程序中显示简单HTML

  •  1
  • Dan J Akhil  · 技术社区  · 16 年前

    here here ),但我需要帮助运行实际的BlackBerry示例代码(或者有人告诉我为什么这注定不起作用!)。

    BlackBerry网站有一些基于不同API版本的“浏览器”代码示例:
    V4.5 API sample
    V5.0 API sample

    我找到了组件包附带的示例代码(更多信息 here ),并尝试使V4.5示例代码正常工作。我希望这将是一个有用的起点。。。

    我已经设法让BrowserFieldDemo在Eclipse中编译并在模拟器中运行(我需要注释掉整个BrowserContentManagerDemo.java,否则该类将运行)。

    不幸的是,我只是在模拟器中得到一个白色屏幕。当我添加日志并使用调试器时,这里的getBrowserContent()行似乎出现了问题:

    BrowserContent browserContent = null;
    
    try
    {
        browserContent = _renderingSession.getBrowserContent(connection, this, e);
        <snip>
    }
    catch (RenderingException re)
    {
      EventLogger.logEvent(ID, (re + "").getBytes(), EventLogger.ERROR);
      System.err.println(re);
    }
    

    net.rim.device.api.browser.field.RenderingException:连接中的IOException

    我尝试过用4.5.0和4.7.0组件包构建和使用模拟器,但它们都有相同的症状。

    如果我将samples.cod文件推送到我的设备并启动它,我会得到“启动示例时出错:模块'samples'尝试访问安全API”。大概我需要用我的代码签名密钥(我确实有)对示例代码进行签名,我不知道在Eclipse中该如何做。

    1) 有人真的有这个V4.5示例代码工作吗?我应该放弃模拟器而改用这个设备吗?

    2) 这个V4.5方法可以用于显示我拥有的一些简单HTML数据吗?e、 我可以使用一个本地主机URL,或者创建一个定制的HttpConnection来提供数据吗?

    如果可能的话,我需要支持运行V4.5、V4.7和V5.0的黑莓机型。

    任何提示都将不胜感激!

    2 回复  |  直到 8 年前
        1
  •  1
  •   Marc Novakowski    16 年前

    确保在启动设备模拟器之前启动MDS模拟器。所有或大多数使用HTTP的示例都没有指定传输,因此将使用默认的MDS传输,这意味着如果您没有运行MDS模拟器,那么它将无法建立HTTP连接。

        2
  •  5
  •   Maksym Gontar    16 年前

    您应该实现自己的HttpConnection,它将在构造函数中接受字符串参数并返回所有值,如getType()、getLength()、openInputStream()上的InputStream等。然后将其与浏览器字段一起使用,就像在sdk BrowserFieldDemo中一样。

    public class HttpConnectionImpl implements HttpConnection {
        private long streamLength = 7000;
        private DataInputStream dataInput;
        private InputStream in;
        private String encoding = "text/html";
    
        public HttpConnectionImpl(String data) {
            try {
                in = new ByteArrayInputStream(data.getBytes("UTF-8"));
                dataInput = new DataInputStream(in);
            } catch (Exception e) {
                System.out.println("HttpConnectionImpl : Exception : " + e);
            }
    
        }
    
        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 encoding;
        }
    
        public long getLength() {
            return streamLength;
        }
    
        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());
        }
    }
    

    See full code with example of use