Tuesday, April 28, 2009

BlackBerry connection tip

We developed a small client application for BlackBerry phones that connects to MiaMia servers. A lot of things can be said about BlackBerry adherence to standards, but I don't want to use cuss words here. The main problem is that these phones were initially devised to serve as "corporate walkie-talkies", and only recently their design was stretched to accommodate the needs of the general public. In a nutshell, this is a hardware equivalent of Lotus Notes - a combination of lack of respect for standards and a kungfu grip on the corporate customers.

As a result, once in a while developers encounter what can be described as a "chastity belt" - when it comes to communications with external world. Look for blackberry connection problems in Google or read this frustrated rant that sums it all. And if, as a BlackBerry user, you encountered problems with MSN Messenger, IRC, or anything else - same reason.

By default, when possible and a proxy-based connection (MDS, BES, BIS) exists, BlackBerry seems to re-route all requests there. It is not at all certain that your tiny app will be allowed to go further. Chances are, it will be stopped, and possibly hang. However, there are two possibilities that should work in most cases:


  • direct TCP/IP via GPRS network
  • wireless connection

To cut the long story short, the easiest way to provide maximum coverage is to create a tiny function that will be used like this:



 protected String getDeviceSpecificUrlParameters()
{
try {
if (net.rim.device.api.system.WLANInfo.getWLANState() == net.rim.device.api.system.WLANInfo.WLAN_STATE_CONNECTED)
{
return ";deviceside=true;interface=wifi;ConnectionSetup=delayed;retrynocontext=true";
}
} catch (Exception e) {} // doesn't matter, just go elsewhere
return ";deviceside=true";
}

then call it whenever you make a connection, e.g.
 ...
Connector.open(url + getDeviceSpecificUrlParameters());
...

If your application is designed to work across different platforms (like ours), you can re-implement that getDeviceSpecificUrlParameters() for whatever platform you need.


A word of warning: if it's a brand new phone, and the access to GPRS is not configured, you may need to explain your users how to set up their APN parameters. The carrier-specific parameters can be found here, here, and here.

3 comments:

Henry Cipolla said...

Vadim,

This post is helpful because it addresses the confusing problem of establishing a network connection on a BlackBerry.

On top of the problem of users who have not properly configured their APN settings (which is unfortunately very common) there is also the issue of accounting for Enterprise users who rely on MDS servers for their communications.

The best solution is to provision for a number of different types of connections and chose the optimum path. There is more info about this on our blog:
http://www.localytics.com/blog/post/how-to-reliably-establish-a-network-connection-on-any-blackberry-device/

Hope this helps,

-- Henry

Vadim Berman said...

Thanks, Henry! Your function covers all the bases.

Maybe one note though: in some cases, it probably would make sense to ignore proxy connection channels in favour of the carrier TCP/IP: the enterprise administrators may have too restrictive policy, and your app will not be allowed to make a connection. But I am not 100% sure about this one.

sukumar said...

very useful message about blackberry. That's very useful to mobile user. Thanks for the post Mobile Application Development