Properly Using Desktop::setScreenSaverEnabled() to Disable Timeouts on Mobile Devices

I’ve been trying to figure this out for quite awhile now and I am going a little stir crazy. Based on research and some of the information in the forums, I’ve been able to determine that the JUCE way to prevent screen timeouts in JUCE applications is to call Desktop::setScreenSaverEnabled(false). This appears to work correctly for me in both iOS and OSX of the same application. However, using the same codebase/implementation on Android results in no prevention of screen fade. Does anyone have any advice or ideas of what could be going on? Same code, same call, and based on the second link, it seems that this SHOULD work for android.

For more context, I am calling Desktop::setScreenSaverEnabled(false); from within my main.cpp at the end of the MainWindow class constructor.

Related posts:

As shows up in the related posts to your topic, I’ve posted the solution to Android here:

You’ll have to implement it natively. There is a step by step instruction for it in that thread

//Edit: I just saw that you even commented on that thread already. Do you have issues with my implementation? It should work and yield your expected results

//Edit2: looking at the second link you posted, yes this SHOULD work on Android… No idea what’s going on if it doesn’t… Try popping in my code, you can copy paste that as is. It works here, just tested it

Your reply actually represents part of my confusion. I have tried both your approach and the native JUCE call. And neither appear to properly disable the screen timeout on either of the android devices I have physically attached to/tested on (Google Pixel 1 and LG 8+). Got any ideas as to what’s happening? Your post makes it sound like your approach works for you.

Edit: Is it possibly related to where I am making the call to disable the screen time out? As I mentioned in my post - I tried your code block and the native juce call at the end of the MainWindow constructor.

Edit 2: For clarity - I am using Projucer/JUCE v.6.0.1 and Android studio v.4.0.0 - I am going to update/try 4.0.1

Edit 3: Update - v4.0.1 of Android studio did not change my lack of screen sleep prevention.

Oh I just saw that you’re doing this at the end of the main window constructor. Try moving your call some other place.
The screen lock calls have to get the main window object on Android, so it should be done constructing when you call that. Just a wild guess, but worth a try imho

Moved it outside into the main run loop of my app (inefficient, I know, but easy enough for a test). Still my android screen fades into black at the predestined system time out. It’s so weird, because this works for iOS and OSX, just not Android… Are you configuring your project in some way that can allow for different access of the components? Like, is there a permissions setting I need to control or something?

I just checked… i have that call to my setAutolockEnabled function in my MainComponent constructor… and it works just fine. There are definitely no additional permissions that need to be set for that and I’m going from a standard juce template…

I have no idea what’s going on at your end unfortunately.

That’s alright. Thank you for your help. Even if I am still stuck :upside_down_face: If I figure it out, I will update for posterity.

Edit: @ benediktsailer Can I ask what version of JUCE you’re using and the target version of android platform you’re using I’ve seen some android code now that maybe indicates there’s a difference in screen sleep protocols after SDK >= 27