Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
Posts: 13
Registered: ‎04-13-2013
My Device: Passport / Q10 / Z10 / PlayBook / Dev Alpha B
My Carrier: Vodafone
Accepted Solution

Preventing screen from turning off (locked)

The screen turns off after a short time, as configured in settings. But sometimes, this should be disabled by software, e.g. the navigation software should not let the display get black. (BlackBerry Maps seems to manage this...)

 

There are other situations, where it could be a good idea to let the display in active mode, maybe for media players (watching video) and so on.

 

The settings page of the device even informs me in Security/Device Password about the fact, that applications could enlarge the time until the device will be locked with this password.

 

But I cannot find any documentation how both of this can be done from code.

What permission is needed and what do I have to call?

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Preventing screen from turning off (locked)

[ Edited ]

Hi,

This code will prevent the screen from locking:

 

#include <bb/cascades/Window>
...
Application::instance()->mainWindow()->setScreenIdleMode(ScreenIdleMode::KeepAwake);

 

 


Andrey Fidrya, @zmeyc on twitter
New Developer
Posts: 13
Registered: ‎04-13-2013
My Device: Passport / Q10 / Z10 / PlayBook / Dev Alpha B
My Carrier: Vodafone

Re: Preventing screen from turning off (locked)

Wow, thanks for that quick answer!

This works indefinitely?
Highlighted
Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Preventing screen from turning off (locked)

Yes, until turned off using the same command with a different parameter.

This can also be done from QML or using C API. This thread has more info:

http://supportforums.blackberry.com/t5/Cascades-Development/prevent-a-screen-lock/m-p/2100313#M11757


Andrey Fidrya, @zmeyc on twitter
New Developer
Posts: 13
Registered: ‎04-13-2013
My Device: Passport / Q10 / Z10 / PlayBook / Dev Alpha B
My Carrier: Vodafone

Re: Preventing screen from turning off (locked)

I wonder why I could not find this thread. I am sure that I have searched for the right keywords...
Thanks a lot!
New Contributor
Posts: 2
Registered: ‎08-10-2013
My Device: dev alpha c
My Carrier: 650946391

Re: Preventing screen from turning off (locked)

It works fine.

 

I have put that line in my app's main .cpp

 

More info:

 

https://developer.blackberry.com/native/reference/cascades/bb__cascades__window.html#function-setscr...