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
Developer
Developer
klz
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
Accepted Solution

prevent a screen lock

Hello guys,

 

I've faced with the following problem. Let's say I have a flashlight app. So I turn flash on on looking for my keys or whatever. But when the screen goes off the flash stops working. 

 

How could I prevent this situation? I've checked the documentation but I can only read screen lock status, not set it.

 

Any help would be appreciated.

 

Thanks! 

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: prevent a screen lock

I don't have a link handy but check the Application class for a mainWindow property, and whatever that type is (MainWindow?) it has something for a keep-awake feature.

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!
Developer
Developer
klz
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook

Re: prevent a screen lock

Thanks a lot Peter,

 

So I've found 3 ways.

1) QML

Application.mainWindow.screenIdleMode = 1

 2) C++

WId winId = this->mainWindow->winId();
if( winId != NULL )
{
  int idleMode = SCREEN_IDLE_MODE_KEEP_AWAKE;
  screen_set_window_property_iv( screen_window_t(winId), SCREEN_PROPERTY_IDLE_MODE, &idleMode);
}

 3)  C++

1) Create a new thread
2) In the thread create a screen context
3) request events for screen and navigator
4) when you get a message of screen idle, inject a touch event into the screen queue

 

 

 

 

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Contributor
paul_shah
Posts: 17
Registered: ‎02-01-2013
My Device: Bold 9900

Re: prevent a screen lock

Hey klz! 

 

I am trying to use the C++ code you provided with my cascades app, in my app.cpp and this line is returning an error: 

WId winId = this->mainWindow->winId();

 Can you please help me out? I did this instead, is it still valid?

 

screen_context_t *pctx;
screen_window_t *win;

screen_create_context(pctx, SCREEN_POWER_MANAGER_CONTEXT);
screen_create_window(win,*pctx);

int idleMode = SCREEN_IDLE_MODE_KEEP_AWAKE;
screen_set_window_property_iv(*win, SCREEN_PROPERTY_IDLE_MODE, &idleMode);

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

Re: prevent a screen lock

paul_shah, if it's a Cascades app, why wouldn't you use klz's option number 1, which is trivial and should work in any Cascades app when translated from the JavaScript syntax to appropriate C++ 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!
Contributor
paul_shah
Posts: 17
Registered: ‎02-01-2013
My Device: Bold 9900

Re: prevent a screen lock

Peter, I tried that but it says there is no member function called mainWindow in Application. Thats where I am having the issue. 

Contributor
paul_shah
Posts: 17
Registered: ‎02-01-2013
My Device: Bold 9900

Re: prevent a screen lock

I think this is the correct line that klz meant to write for cascades: 

 

Window *winId = Application::instance()->mainWindow();

if( winId != NULL )
{
int idleMode = SCREEN_IDLE_MODE_KEEP_AWAKE;
screen_set_window_property_iv( screen_window_t(winId), SCREEN_PROPERTY_IDLE_MODE, &idleMode);
}

 

I think that should do the job

Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: prevent a screen lock

Hi Paul,

 

Try:

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


Andrey Fidrya, @zmeyc on twitter
Developer
javayoung
Posts: 313
Registered: ‎05-31-2010
My Device: Alpha 10, Bold 9900, Storm 9530, Tour 9630, Curve 9320, Curve 8900

Re: prevent a screen lock

I have tried but it has the following errors.

 

(1)forward declaration of 'struct bb::cascades::Window' 
(2)invalid use of incomplete type 'struct bb::cascades::Window'





p(^_^)q
Good good study, day day up
Developer
Developer
klz
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook

Re: prevent a screen lock

I've already used the first solution for 4 or 5 apps. And it works properly. 

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com