(Photo credit to Alan L, and his cat)
When your content is so riveting that your users can’t take their eyes off the screen, the last thing you want is the screen dimming and breaking that immersion. Thankfully, BlackBerry 10 offers a simple API to keep the screen from dimming, which conveniently handles things like the user putting the application in the background. Just a few weeks ago, I wrapped up this simple API in a WebWorks Extension using our new Extension Template. I’ve already heard from a few happy developers who have included it in their apps, but there are plenty of use cases, so I figured it would be good to share with the wider developer community. Just remember to use this one properly – turn it on only when displaying content where the user is going to be viewing the screen but not interacting with it. Your users will thank you for being able to see your content, and also for not keeping the screen on when it’s not necessary.
Here’s a quick look at what it’s like to integrate the API.
Add the feature to your config.xml:
<feature id="community.preventsleep" required="true" version="18.104.22.168" />
And call these methods to interact with it:
var setting = true; // boolean var result = community.preventsleep.setPreventSleep(setting); // Result is a string value for debugging var currentSetting = community.preventsleep.isSleepPrevented; // boolean value for the state of the screen
Thanks for checking it out and if you’ve got any issues, please post them on GitHub. Now your slideshow app of animated cat gifs can be realized in all its deserving glory.