BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   wifi: works in browser and apps, but not in our program (http://www.blackberryforums.com/developer-forum/248960-wifi-works-browser-apps-but-not-our-program.html)

maykivets 05-17-2011 05:36 AM

wifi: works in browser and apps, but not in our program
 
Hello everyone,

we have just started to write Blackberry apps and got strange situation. Our apps work with mobile internet (GPRS, 3G, EDGE) but are not working using wifi connection.

I have tried to change all the settings. But still usually it is just "Tunnel failure" or "connection timed out". The same is with HTTPDemo example.

Could someone help and explain what it is with Blackberry and 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;
}

hrbuckley 05-17-2011 08:21 AM

Re: wifi: works in browser and apps, but not in our program
 
Ok, first please read this post so the code you post will be easier to read.

1. What OS version are you using?

2. Do you have a BlackBerry Data Plan on the device?

3. Have you configured the appropriate APN values for your carrier?

maykivets 05-17-2011 09:23 AM

Re: wifi: works in browser and apps, but not in our program
 
@hrbuckley
thanks
Here are the answers to your questions:
1. 5.0
2. It works now even without Data Plan (with the code below).
3. Is it really necessary for the wifi connections?

PHP Code:


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



hrbuckley 05-17-2011 04:58 PM

Re: wifi: works in browser and apps, but not in our program
 
Glad to hear you got it working.

2. Depending on the carrier and the OS level Wi-Fi won't work without one.
3. No, but again, depending on the OS level and carrier support the else clause from your code above won't work without the APN configured, usually the earlier OSes need an APN.


All times are GMT -5. The time now is 01:09 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.