Blackberry wifi http connection

2019-02-20 20:27发布

问题:

I am building a blackberry application takes input from user then send input to a server and displays the xml returned from server.

The problem is, while application works fine on simulator it doesn't show results all the time on real device. Sometimes it is working but usually it's not. I am using wifi connection on device. The code is:

Connector.open(url + ";interface=wifi");

I am not using wifi on simulator. I just delete the 'interface=wifi' part and it runs using mds.

When input taken, a class extending Thread starts. It opens the connection and initializes variables. I take the inputstream from class and parse the xml. The device is a Blackberry 9700.I read something about connection timeout but i am not sure where problem is.

Edit: Found a simple way to connect. Here is the code for a GET request:

ConnectionFactory cf = new ConnectionFactory();
ConnectionDescriptor cd = cf.getConnection("YourUrl");
httpConnector = (HttpConnection) cd.getConnection();
httpConnector.setRequestMethod(HttpConnection.GET);

回答1:

Maybe this might help: http://www.localytics.com/blog/2009/how-to-reliably-establish-a-network-connection-on-any-blackberry-device/

The idea in that blog post is to check if WiFi is enabled, and in that case use that for connection string, and so on for various connection types.