1
votes

I am trying to build a simple application for testing purpose in which I am making a simple Http connection .The code is running perfectly on the simulator but when I am testing the app on the real device it is not returning any response code. I think there is some error in http connection .

Here is the code that I am using for http connection:

httpConnection = (HttpConnection)Connector.open("http://www.google.com"); 

The device that I am using is Blackberry 8520 v5.0.0.592

Also give me some tips on how to do the debuging of any app from real device using eclipse plugin.

Thanks in advance.

4
First things to check are: does the device have a BlackBerry Data Plan activated for it? If not insure that the APN is configured properly and try appending ;deviceSide=true to the URL: "google.com;deviceSide=true"Richard
Yes the device has BB Data Plan. I have tried using deviceSide=true ,also enabled the APN setting leaving username and password blank. But it didnt work for me.Dinesh Sharma
How did you specify the APN settings? What operator do you have?hrnt
Also, what BlackBerry OS versions do you need to support? If only 5.0 and newer, you should use the new Network API instead.hrnt

4 Answers

2
votes

If it is enough that your program works with OS 5.0+, then try using Network API:

ConnectionFactory f = new ConnectionFactory();
ConnectionDescriptor descr = f.getConnection("http://www.google.com");

HttpConnection connection = (HttpConnection) descr.getConnection();

That piece of code tries to use the first available connection type. You can fine tune it if you want.

Regarding debugging, just install BlackBerry Desktop Software, connect your 8520 with the USB cable and from eclipse, click Run -> Debug As... -> BlackBerry Device.

1
votes

The connection factory worked perfectly on the new devices, but didn't work with some of the older ones like the curve and bold. This is what solved it for me:

BrowserField browserField = new BrowserField();
BrowserFieldRequest Req = new BrowserFieldRequest("http://www.yourserver.com/");

InputStream inputStream = browserField.getConnectionManager().makeRequest(Req).openInputStream();
1
votes

Try to redirect the link using following code:

 HttpConnection hc = (HttpConnection) Connector.open(url1);

 hc.setRequestMethod(HttpConnection.GET);
 hc.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
 InputStream is = null;
 String location =hc.getHeaderField("Location");

 HttpConnection hcc = (HttpConnection) Connector.open(location);
 is = hcc.openDataInputStream();
0
votes

Try to add transport to address For example for connect via wi-fi :

httpConnection = (HttpConnection)Connector.open("http://www.google.com;interface=wifi");