【问题标题】:wifi doesn't work in own apps, but works in blackberry's browserwifi在自己的应用程序中不起作用,但在黑莓的浏览器中起作用
【发布时间】:2024-01-17 14:05:02
【问题描述】:

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

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

有人可以帮忙解释一下黑莓和 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;
           } 

【问题讨论】:

    标签: blackberry wifi


    【解决方案1】:

    按照以下方式连接对我有用

    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 by peter_strange

    【讨论】:

      最近更新 更多