Back

CreatePhoneState

Hello World
Content:
- Methods

The PhoneState component is able to detect phone state changes.

pst = app.CreatePhoneState( types ) → app object: PhoneState

The callback data depends on the type:

“CellLocation” : object: { cellId, areaCode }
“DataConnection” : object: { state, networkType }
“DataActivity” : unknown
“CallState” : object: { state, number }
“ServiceState” : string: “OutOfService”
“SignalStrength” : number: float
“CallForwarding” : boolean
“MessageWaiting” : boolean

Example - Demo

function OnStart()
{
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );

    txt = app.CreateText( "", 0.95, 0.95, "multiline,left" );
    txt.SetTextSize( 14 );
    lay.AddChild( txt );

    app.AddLayout( lay );

    var types = "CellLocation,DataConnection,DataActivity,CallState,"
        + "ServiceState,SignalStrength,CallForwarding,MessageWaiting";

    state = app.CreatePhoneState( types );
    state.SetOnChange( state_OnChange );
    state.Start();
}

var log = [];
function state_OnChange( type, data )
{
    log.push( type.bold() + ":<br>\t" + JSON.stringify(data) );
    txt.SetHtml( log.join("<br>") );
}
Copy All       Run      

Methods

The following methods are available on the PhoneState object:

GetType() → string: “PhoneState”
Start()
Stop()
number: integer
string: number
string: “CellLocation”, “DataConnection”, “DataActivity”, “CallState”, “ServiceState”, “SignalStrength”, “CallForwarding”, “MessageWaiting”
string: “Connected” or “Disconnected”
string: “Unknown”
string: “Idle”
function( type, data )
pst.GetType
Returns the control class name.
pst.SetOnChange
Define a callback function which is called when a phone state has changed.
pst.Start
Start listening.
pst.Stop
Stop listening.