Pages

Wednesday 29 August 2012

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.

<rim:connection timeout="25000">
<id>TCP_WIFI</id>
<id>BIS-B</id>
<id>TCP_CELLULAR</id>
<id>MDS</id>
<id>WAP2</id>
<id>WAP</id>
</rim:connection>   


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.

No comments:

Post a Comment

About the Author

I have more than 10 years of experience in IT industry. Linkedin Profile

I am currently messing up with neural networks in deep learning. I am learning Python, TensorFlow and Keras.

Author: I am an author of a book on deep learning.

Quiz: I run an online quiz on machine learning and deep learning.