Phonegap on Blackberry: 2 Programming Tips


I am creating an application using phonegap which will run on blackberry, android and iPhone. For now, I am just trying to run it on blackberry. I found two things important which I thought I must share. Maybe someone can give me better idea and more tips!!

1. Add type and order of the transport methods to be used by blackberry device in the config file.

TCP_WIFI
BIS-B
TCP_CELLULAR
MDS
WAP2
WAP
  


2. Always use deviceready event listener to check connection on the blackberry device

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() 
{
   checkConnection();
}

function checkConnection() 
{
var networkState = navigator.network.connection.type;
var states = {};
states[Connection.UNKNOWN]  = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI]     = 'WiFi connection';
states[Connection.CELL_2G]  = 'Cell 2G connection';
states[Connection.CELL_3G]  = 'Cell 3G connection';
states[Connection.CELL_4G]  = 'Cell 4G connection';
states[Connection.NONE]     = 'No network connection';
if(states[networkState]=="No network connection")
{
alert("No Connection Available");
navigator.app.exitApp();
}        
}


Note: While running your code on web browser, you need to comment the above code as deviceready event listener is meant only for device not web browser. It may throw a javascript error while running on web browser.