Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

What Is - Network API alternative for legacy OS

by BlackBerry Development Advisor ‎10-18-2010 03:17 PM - edited ‎03-14-2011 05:11 PM (32,234 Views)

 

The Network API was first introduced in BlackBerry® Device Software 5.0 to make network connectivity a breeze for developers. The primary goal of the Network API was to serve two basic use cases:

  1. Detect what transports are available.
  2. Create a connection over one of the available transports.

However, there are a lot of users who may not be running BlackBerry Device Software 5.0 and hence applications are unable to leverage the Network API in those cases. Keeping this in mind, I decided to put together an alternative API with source that developers can use out-of-the-box or extend as they see appropriate in BlackBerry Device Software earlier than 5.0. This open API consists of two simple classes.

 

TransportDetective: Allows an application to quickly detect what transports are available.

URLFactory: Appends proper parameters to a given URL to connect over a specific transport.

 

To demonstrate how easy it is to use these classes, here is a snippet that creates a connection over WAP2.

 

 

 

 

 

 

 

TransportDetective td = new TransportDetective();
boolean isWap2Available = td.isCoverageAvailable(TransportDetective.TRANSPORT_WAP2);
if(isWap2Available){
URLFactory urlFactory = new URLFactory("http://www.blackberry.com"); String connectionURL = URLFactory.getHttpWap2Url(td.getSrWap2); try{ HttpConnection connection = (HttpConnection)Connector.open(connectionURL); ... } catch(IOException){ // handle connection exception... } }

 

Similarly, you can use other transports such as TCP WiFi, TCP Cellular, MDS, BIS and WAP. Both socket and HTTP based connection URLs are supported including secured protocols such as SSL, TLS and HTTPS.

 

You may also be familiar with the Network Diagnostic Tool which can be used to quickly test specific transports with a given URL. It is worth mentioning that the latest version of the Network Diagnostic Tool is based on Transport Detective and URLFactory. The source code of this tool is also open. You can download this tool as well as the open Network API today using the links at the end of this article.

 

Related resources

Tutorial

Network Transports

 

Videos

Network Transports

Networking Transports II

 

 

 

 

 

 

Comments
by Developer on ‎10-25-2010 01:18 PM

This is great. Thanks for posting.

by Developer on ‎11-12-2010 04:11 AM

I have just glanced over it, i think it is a very good tool but misses a few things to be outstanding.

- storing the last valid connection to avoid checking it for every single call

- listening for coverage changes to reset the last valid connection

- using a limited number of threads for connections, not one for each like the IOThread

by Developer on ‎02-21-2011 10:55 AM

Very helpful sample. just a quick question:

 

Does TransportDetective tells you that if the device has APN setting configured or not? As per the comments shown below, I recon it does. But when I test on my device, it never tells me that the device has APN configured even if I configure APN settings.

 

public static final int TCP_CELLULAR_APN_SERVICE_BOOK  = 64;     

// Represents the availability of TCP_CELLULAR service book that has APN information pre-populated. Please note that this is not a new transport. This simply indicates that your application do  not need to know the APN information for TCP_CELLULAR since the device already knows it. Please see URLFactory.getHttpTcpCellularUrlUsingServiceRecord(ServiceRecord tcpServiceRecord)  

 

 

And is that any more sample available with outstanding things recommended by Simon?

 

Many Thanks

Nitin

by BlackBerry Development Advisor ‎03-04-2011 12:25 PM - edited ‎03-04-2011 12:28 PM

Hi Nitin,

TCP_CELLULAR_APN_SERVICE_BOOK  refers to something different than what you are looking for. There are three ways the device can get the APN information.

 

1. User setting it in device options.

2. Application providing it as a parameter.

3. Device reading it from a service book if it is present.

 

TCP_CELLULAR_APN_SERVICE_BOOK  is related to the #3. Note that #3 is available only on 6.0 AT&T devices at this point. However, you are trying to detect if #1 is available. There is a new API in 6.0 that does exactly that. Please refer to TcpCellularOptions.isDefaultAPNSet(). Prior to 6.0, there is no way to detect that.

 

Shadid

 

 

by Developer on ‎03-04-2011 12:32 PM

Thanks Shaque,

 

Very useful clarification.

 

Nitin