Back

CreatePhoneState

JS Py
Hello World
Content:
- Properties
- 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>") );
}
from native import app

def OnStart():
    global txt, log
    lay = app.CreateLayout("linear", "VCenter,FillXY")

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

    app.AddLayout(lay)

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

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

log = []

def state_OnChange(type, data):
    log.append("§b§" + type + ":§b§<br>\t" + str(data))
    txt.SetHtml("<br>".join(log))
Copy All       Run      

Properties

The following properties are available on the PhoneState object:

dataObject: { key, value }

Methods

The following methods are available on the PhoneState object:

GetType() → String: “PhoneState”
Start()
Stop()
all types
String
Number: integer
String: number
String: separated: “CellLocation”, “DataConnection”, “DataActivity”, “CallState”, “ServiceState”, “SignalStrength”, “CallForwarding”, “MessageWaiting”
String: “Connected” or “Disconnected”
String: “Unknown”
String: “Idle”
Object: { command: args }
function( type, data )
pst.Batch
Batch method calls to be able to set all object's properties at once.
Note that you need to specify each parameter (use “” or null to leave some out)
Inherited methods can be called by appending an underscore to the function name (ie. txt.Batch({ SetBackColor_: [“red”] })
pst.data
An object for saving individual extra properties.
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.