2012-04-03 32 views
0

嗨我是黑莓應用程序開發中的新手,我想在瀏覽器字段中加載HTML .. 我可以加載HTML版本5和6以及更多,但它不加載在操作系統版本4在Blackberry4.6操作系統版本上加載html

plz告訴我如何使用Eclipsed 在Blackberry OS版本4.6上加載這個HTML到5和6的應用程序正常工作,但在4.6沒有PLZ告訴我如何寫。代碼爲這個或任何特定的代碼更改或我們不能加載HTML在操作系統版本4.6?

BrowserField mybroBrowserField=new BrowserField(); 

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

這個代碼適用於5和超過5版本,但對於操作系統版本無法正常工作4

+0

請不要轉發問題。 – 2012-04-04 09:29:30

回答

0

BrowserField因爲黑莓5.0.0 API只存在,但你可以使用此自定義BrowserFieldRenderer class從LogicMail爲您解決問題

+0

我們將如何把這個類可以告訴我,因爲我已經嘗試這個不能做.. – 2012-04-04 05:16:20

2

您可以用這種方式顯示你的HTML文檔

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

我也試過這個也不工作。只是告訴我如何加載Html在瀏覽器提交。 in Os版本4.6 – 2012-04-04 05:20:02

+0

它適用於我,BrowerSession可以從4.0版本獲得。如果你可以發佈你的代碼,你到底在做什麼,那麼我將能夠解決問題 – Nsr 2012-04-04 05:22:24

+0

代碼是上我只想要世界,這是在HTML格式只是看到和PLZ告訴我修改後的代碼。此代碼是5和超過5版本的工作,但是當我在4.6運行此代碼不工作。 – 2012-04-04 05:29:33

0

如果您正在使用黑莓Eclipse插件開發的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)方法這一點。

相關問題