Reputation: 15
Can any one help me in knowing the connection type using Worklight API?
I tried using getNetworkInfo(callback)
but not helpful knowing whether 2G or 3G for both iPhone and Android.
Upvotes: 0
Views: 277
Reputation: 44516
Worklight apps are bundled with a version of Cordova.
You can thus use the Cordova Connection API.
With this API you will be able to discern between 2G and 3G connection types and others.
For example, in your-project\apps\your-app\common\js\main.js
, add the following to wlCommonInit()
:
function wlCommonInit() {
var networkState = navigator.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.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
Worklight apps are generated with all required configuration (config.xml, etc...), so no further setup is needed; just adjust the code snippet to your app.
With my iPhone 5s and the specific carrier I am using, I got "Cell generic connection" when using 3G, and "WiFi connection" when using WiFi. So this depends on your carrier setup as well I suspect, but this API does what you asked for.
Upvotes: 2