wifi无法在自己的应用程序中运行,但可以在黑莓的浏览器中运行

时间:2011-05-17 10:40:38

标签: blackberry wifi

我们刚刚开始编写Blackberry应用程序并且遇到了奇怪的情况。我们的应用程序适用于移动互联网(GPRS,3G,EDGE),但无法使用wifi连接。

我试图更改所有设置。但通常只是“隧道故障”或“连接超时”错误。 HTTPDemo示例也是如此。

有人可以帮助解释Blackberry和WiFi的用途吗?

StreamConnection s = null;                    s =(StreamConnection)Connector.open(getUrl()+“; interface = wifi”);                    HttpConnection httpConn =(HttpConnection)s;

               int status = httpConn.getResponseCode();

               if (status == HttpConnection.HTTP_OK)
               {
                   // Is this html?
                   String contentType = httpConn.getHeaderField(HEADER_CONTENTTYPE);
                   boolean htmlContent = (contentType != null && contentType.startsWith(CONTENTTYPE_TEXTHTML));

                   InputStream input = s.openInputStream();

                   byte[] data = new byte[256];
                   int len = 0;
                   int size = 0;
                   StringBuffer raw = new StringBuffer();

                   while ( -1 != (len = input.read(data)) )
                   {
                       // Exit condition for the thread. An IOException is 
                       // thrown because of the call to  httpConn.close(), 
                       // causing the thread to terminate.
                       if ( _stop )
                       {
                           httpConn.close();
                           s.close();
                           input.close();
                       } 
                       raw.append(new String(data, 0, len));
                       size += len;    
                   }   

                   raw.insert(0, "bytes received]\n");
                   raw.insert(0, size);
                   raw.insert(0, '[');
                   content = raw.toString();

                   if ( htmlContent )
                   {
                       content = prepareData(raw.toString());                                
                   }     
                   input.close();                      
               } 
               else 
               {                            
                   content = "response code = " + status;
               }  
               s.close();                    
           } 
           catch (IOCancelledException e) 
           {       
               System.out.println(e.toString());                        
               return;
           }
           catch (IOException e) 
           {       
               errorDialog(e.toString());                        
               return;
           } 

1 个答案:

答案 0 :(得分:2)

连接以下方式对我有用

HttpConnection connection = null;
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
         connection = (HttpConnection) Connector.open(url+ ";interface=wifi",
         Connector.READ_WRITE,true);
} else {
         connection = (HttpConnection) Connector.open(url+";deviceside=true", Connector.READ_WRITE,true);
}

请参阅以下资源,以获得深入的了解和各种方法。

Sample HTTP Connection code and BIS-B Access来自peter_strange