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
Contributor
Posts: 23
Registered: ‎03-01-2013
My Device: Dev Alpha A+C. Playbook.
My Carrier: Tele2, Sweden
Accepted Solution

Prevent screensaver and wake up from sleep

Is there a "Cascades" way of preventing the screensaver? I am also interested in waking the device and turn off the screensaver from code.

 

There is this way of doing it in native:

int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
screen_set_window_property_iv(screen_window,
    SCREEN_PROPERTY_IDLE_MODE, &idle_mode);

But I am hoping there is a nicer way of doing the same way in Cascades and/or Qt?

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Prevent screensaver and wake up from sleep

From my code here:

    onKeepAwakeChanged: {
        // This should be keepAwake ? ScreenIdleMode.KeepAwake : ScreenIdleMode.Normal
        // but the enum is broken in QML
        Application.mainWindow.screenIdleMode = keepAwake ? 1 : 0;
    }

The comment may be obsolete. If not, obviously use the enum in preference to hardcoding the 1 and 0.

 

You could do this from C++ too, where the enum will definitely work but obviously with slightly different syntax.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Highlighted
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Prevent screensaver and wake up from sleep

Cascades equivalent to the above code:

 

#include <bb/cascades/Window>

Application::instance()->mainWindow()->setScreenIdleMode(ScreenIdleMode::KeepAwake);

 


Andrey Fidrya, @zmeyc on twitter
Contributor
Posts: 23
Registered: ‎03-01-2013
My Device: Dev Alpha A+C. Playbook.
My Carrier: Tele2, Sweden

Re: Prevent screensaver and wake up from sleep

Thank you both. Could the same method be used to turn the screensaver off if the device is already in idle?

 

My application uses a bluetooth barcode scanner as the main input and it would be nice to wake up the device when I receive data from the scanner.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Prevent screensaver and wake up from sleep

I believe waking it up is not currently possible with APIs available to us. What you could do for now is use the Notification system to signal the user (audibly and with the LED) that there's a reason to bring the device out of standby.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 23
Registered: ‎03-01-2013
My Device: Dev Alpha A+C. Playbook.
My Carrier: Tele2, Sweden

Re: Prevent screensaver and wake up from sleep

Signaling using the led is nothing for my application. It is the user who uses the reader so notifying makes no sense. But preventing the screensaver is good enough. Thanks.