Skip to content

API: Cellular Signal

Aric edited this page Jul 18, 2014 · 3 revisions

Enable:

@return - String, 'enabled'
@callback - String, function name when listener fires.
window.cellsignal.enable({callback:'cellularSignal', success:cellEnabled});

This plugin adds a phoneStateListener returning the current cellular level when the level changes. When a change occurs the plugin uses 'this.webView.sendJavascript()' to trigger the passed function.

Notice that the triggered function is passed as a string. This is because the sendJavascript builds the function call and then is evaluated once inside the webview.

Disable:

@return - String, 'disabled'
window.cellsignal.disable({success:cellDisabled});

Cellular Level Conversion:

As to negate any issues, the cellular level is not passed converted to an easily managed scale. This allows for custom changes if there are any qualms with the level conversion.

function cellularSignal(returnVal){
var maxStrength = -100;
var minStrength = -70;
var percentage = Math.round(100 - Math.max(0, Math.min((returnVal - maxStrength) / (minStrength - maxStrength), 1) * 100));
$('#cellSignal h3').text(percentage+'%');
}