LightSensor Component


Properties

available
  Specifies whether or not the device has the hardware to support the LightSensor component.
Data type: boolean
Designer Writable false
Code Writeable false
Code Readable true let variable = lightsensorName.available

averageLux
  Returns the brightness in lux by averaging the previous 10 measured values. The sensor must be enabled and available to return meaningful values.
Data type: number
Designer Writable false
Code Writeable false
Code Readable true let variable = lightsensorName.averageLux

enabled
  Specifies whether the sensor should generate events. If true, the sensor will generate events. Otherwise, no events are generated.
Data type: boolean
Designer Writable true <lightsensor name="lightsensorName" enabled="true">
Code Writeable true lightsensorName.enabled = true
Code Readable true let variable = lightsensorName.enabled

lux
  Returns the last measured brightness in lux. The sensor must be enabled and available to return meaningful values.
Data type: number
Designer Writable false
Code Writeable false
Code Readable true let variable = lightsensorName.lux

refreshTime
  The requested minimum time in milliseconds between changes in readings being reported. Android is not guaranteed to honor the request. Setting this property has no effect on pre-Gingerbread devices.
Data type: number
Designer Writable true <lightsensor name="lightsensorName" refreshTime="1000">
Code Writeable true lightsensorName.refreshTime = 1000
Code Readable true let variable = lightsensorName.refreshTime

class
  The styling class of the the component
Data type: string
Designer Writable true <lightsensor name="lightsensorName" class="Test class">
Code Writeable false
Code Readable false

id
  The styling id of the the component
Data type: string
Designer Writable true <lightsensor name="lightsensorName" id="Test id">
Code Writeable false
Code Readable false

name
  The name of the component that will be used to refer to it in code.
Data type: string
Designer Writable true <lightsensor name="lightsensorName" name="testComponent">
Code Writeable false
Code Readable false

Methods

Method name Description Parameters
addEventListener Method used to create event listeners.
See Events below for samples.
eventName string
eventCallbackFunction callback

Events

Event name Description Parameters
lightChanged Indicates the light level changed.
lightsensorName.addEventListener(
    "lightChanged",
    function (lux) {
        //Your code here
    }
)
lux number