Hi all,
Working on a project where the client has requested a "night mode" in the app
Using the battery event I can detect when the device has been unplugged and plugged back in. However, it will only trigger event when a 5% battery change occurs. This causes problems if there isn't a 5% change in battery level, for example, someone reconnects device when its at 97%, the event doesn't appear to get triggered.
Granted, this is something of an edge case but I think it is probably fairly prevalent
Ti.Platform.addEventListener("battery", function(e) { if (e.state == Ti.Platform.BATTERY_STATE_UNPLUGGED) { alert("Enter night mode"); } else if (e.state == Titanium.Platform.BATTERY_STATE_CHARGING || e.state == Titanium.Platform.BATTERY_STATE_FULL) { alert("Day mode"); }; });