一千萬個為什麽

搜索

使用Blackberry BrowserField在我的應用程序中顯示簡單網頁


我想要做的是在我的應用程序中顯示一個簡單的網頁(沒有javascript,cookie或任何腳本,而不是試圖檢測任何事件,如鼠標點擊等)。

我正在使用下面的代碼,現在我得到的只是空屏幕..我知道應用程序正在訪問互聯網(數據傳輸箭頭在右上角閃爍)但不確定為什麽它不渲染。

我使用的代碼是:

HttpConnectionFactory factory = new HttpConnectionFactory("www.google.ca",HttpConnectionFactory.TRANSPORT_WIFI | HttpConnectionFactory.TRANSPORT_WAP2 | HttpConnectionFactory.TRANSPORT_DIRECT_TCP);

while(true)
{
     try
     {
          HttpConnection connection = factory.getNextConnection();
          try
          {
              BrowserContent bc = RenderingSession.getNewInstance().getBrowserContent(connection,null,0);
              Field f = bc.getDisplayableContent();
              add(f);  
          }
          catch(RenderingException e)
          {
              //Log the error or store it for displaying to
              //the end user if no transports succeed
              System.out.println("error with rendering page");
          }
    }
    catch(NoMoreTransportsException e)
    {
           //There are no more transports to attempt
           //Dialog.alert( "Unable to perform request" ); //Note you should never
           //attempt network activity on the event thread
           System.out.println("no more transport");
           break;
    }
}

有些要點需要註意:

  1. 我正在使用www.versatilemonkey.com上的http-connection-factory類,因為他們已經實現了抽象的httpConnection類。如果有人也可以指出我如何實現我自己的那將是偉大的。

  2. 我使用'0'作為getBrowserContent函數的標誌。我查看了rimn文檔,但找不到對它們的解釋。

任何幫助將不勝感激。

謝謝, ANKIT

最佳答案

Are you running this in a simulator or real device. If on a real device, what carrier are you on? The reason I ask is that if you're on a GSM network (such as AT&T or T-Mobile in the US), you will most likely need to have an APN configured in your device settings or specified on the connection URL. Taking a peek at the code for the HTTP connection library you're using, I don't see anything in there to append APN settings to the URL - so if it's not configured in the device settings than Direct TCP won't work. That leaves WAP2 and Wi-Fi - not all devices have Wi-Fi and from my experience not all devices/carriers support WAP2, either.

轉載註明原文: 使用Blackberry BrowserField在我的應用程序中顯示簡單網頁

猜你喜歡