■ Platform
Android
iOS
■ Documentation : https://www.npmjs.com/package/cordova-plugin-flashlight
Code: Select all
Enumeration
#mf
#mfSwitch
EndEnumeration
Declare PluginInit(onSuccess, onError)
Declare Start()
Declare OnClick()
Declare OnError()
;No debug
CloseDebugOutput()
;Import Cordova Plugin
Import "cordova plugin add cordova-plugin-flashlight"
EndImport
;Init plugin
PluginInit(@Start(), @OnError())
Procedure PluginInit(onSuccess, onError)
!window.plugins.flashlight.available(function(isAvailable) {
! if (isAvailable) {
! v_onsuccess();
! } else {
! v_onerror();
! }
!})
EndProcedure
Procedure Start()
Protected Font = LoadFont(-1, "Arial", 20)
OpenWindow(#mf, 0, 0, 0, 0, "Flash Light", #PB_Window_Background)
SetWindowColor(#mf, RGB(105, 105, 105))
ButtonGadget(#mfSwitch, 20, 50, WindowWidth(0)-40, 200, "Light On")
SetGadgetFont(#mfSwitch, FontID(Font))
;Trigger
BindGadgetEvent(#mfSwitch, @OnClick())
EndProcedure
Procedure OnClick()
Static Status
If Status
Status = #False
SetGadgetText(#mfSwitch, "Light On")
! window.plugins.flashlight.switchOff()
Else
Status = #True
SetGadgetText(#mfSwitch, "Light Off")
! window.plugins.flashlight.switchOn()
EndIf
EndProcedure
Procedure OnError()
!alert("Flashlight not available on this device")
EndProcedure