Here is some code from main.lua. I found it’s important to not do any canvas drawing prior-to for it to work properly (do it all in whatever scene is loaded next).
For my games, this has resolved the issue with Android 4 in all cases, and Android 5 except for when the users presses the square soft-button to reenter the app, but if the user uses the app icon to reenter the game (i.e., pressed the circle soft-button first and then app icon) it works fine. Too many problems on Android 6, so I left it as lowProfile (only about 1 percent of my users are on Android 6).
One last note: I set the onResizeTimer to 2000ms. I did some testing here - 1000ms seemed to work in most cases, 1500ms in all cases I tested, so I did 2000ms to be safe. Obviously, the longer this number is, the longer the app will take to load for Google users for whom immersiveSticky doesn’t apply.
[lua]
G_screenW, G_screenH, G_halfW, G_halfH = display.contentWidth, display.contentHeight, display.contentWidth*0.5,
–etc, put other global positioning vars here
local onResizeTimer, onResize, onResizeFix, fixTimer
function onResizeFix( event )
if fixTimer then timer.cancel(fixTimer) fixTimer = nil end
fixTimer = timer.performWithDelay(1000, function() native.setProperty( “androidSystemUiVisibility”, “immersiveSticky” ) end)
end
function onResize( event )
G_screenW, G_screenH, G_halfW, G_halfH = display.contentWidth, display.contentHeight, display.contentWidth*0.5,
--etc, put other global positioning vars here
Runtime:removeEventListener( “resize”, onResize )
if onResizeTimer then
timer.cancel( onResizeTimer )
onResizeTimer = nil
Runtime:addEventListener( “resize”, onResizeFix ) --we do this here because if the timer isnt nil, then we know the game loaded via a resize event and will need the resize fix applied
end
composer.gotoScene( “loadingScene” )
end
local androidVersion = tonumber(string.sub(system.getInfo(“platformVersion”),1,1))
if platform == “google” and system.getInfo(“environment”) == “device” and androidVersion then
if androidVersion >= 4 and androidVersion < 6 then
Runtime:addEventListener( “resize”, onResize )
native.setProperty( “androidSystemUiVisibility”, “immersiveSticky” )
onResizeTimer = timer.performWithDelay( 2000, function() onResizeTimer = nil; onResize() end )
else
native.setProperty( “androidSystemUiVisibility”, “lowProfile” )
onResize()
end
elseif platform == “google” then
native.setProperty( “androidSystemUiVisibility”, “lowProfile” )
onResize()
else
onResize()
end
[/lua]