Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Battery state - some potential design and logic flaws in SDK?

$
0
0

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");
};
});

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>