I made an app that simply sends a signal to a google spreadsheet when shaken. The app works fine but the problem is after several hours (or shorter time) the app works after the second shake only. That means there is Android mechanism that possibly turns on the phone after first shake; however, the code I have below only triggers after the second shake. Is there a way to keep the phone all the time.
Just to note that this phone can keep the screen on all the time while some phones wont allow that (there are apps that keep screen on infinitely if your phone wont allow doing that).
My question is “Is there an actual mechanism in Android which makes the phone sleep and wakes up after the first shake? Is there a way to avoid this?” Thanks in advance.
local json = require "json" local widget = require( "widget" ) -------- -- Text parameters local labelx = 50 local x = 150 local y = 150 local fontSize = 16 display.setDefault( "anchorX", 0.0 ) -- default to TopLeft anchor point for new objects display.setDefault( "anchorY", 0.0 ) local xilabel = display.newText( "instant x = ", labelx, y, native.systemFont, fontSize ) local xi = display.newText( "0.0", x, y, native.systemFont, fontSize ) xilabel:setFillColor(0,0,0) xi:setFillColor(0,0,0) y = y + 20 local yilabel = display.newText( "instant y = ", labelx, y, native.systemFont, fontSize ) local yi = display.newText( "0.0", x, y, native.systemFont, fontSize ) yilabel:setFillColor(0,0,0) yi:setFillColor(0,0,0) y = y + 20 local zilabel = display.newText( "instant z = ", labelx, y, native.systemFont, fontSize ) local zi = display.newText( "0.0", x, y, native.systemFont, fontSize ) zilabel:setFillColor(0,0,0) zi:setFillColor(0,0,0) y = y + 20 local tilabel = display.newText( "Timer = ", labelx, y, native.systemFont, fontSize ) local ti = display.newText( "0.0", x, y, native.systemFont, fontSize ) tilabel:setFillColor(0,0,0) ti:setFillColor(0,0,0) ------------------------- --POST to Google Sheet local function getFeatured(event) print(event.response) end --POST to Google Sheet local myText = display.newText("(Waiting for response)", display.contentCenterX, 120, native.systemFont, 16) myText:setFillColor(0,0,0) local function xyzFormat( obj, value) obj.text = string.format( "%1.3f", value ) end local function loadall() headers = {} local params = {} --params.headers = headers params.body = "name=someVal&comment=someOtherVal" network.request( "https://script.google.com/macros/s/AKfycbxZS9y-d97VEKZw2aaqAD746wspoleBbRN92RT9h-FP3OQmeVwV/exec","POST",getFeatured,params) end local function onAccelerate( event ) if event.xInstant\>0.5 then xyzFormat( xi, event.xInstant) xyzFormat( yi, event.yInstant) xyzFormat( zi, event.zInstant) xyzFormat( ti, system.getTimer()) loadall() end end Runtime:addEventListener ("accelerometer", onAccelerate);