Wake Lock screen permission for Android mobile devices

Hello guys!

So, for the last couple of months I’ve been working on the H.I.I.T. Timer app (High Intensity Interval Training). I didn’t find what I needed on Android Play Store so I figure out “why not do it myself?”. Anyway…

Right now I’m almost done. But unfortunately only just now I’ve noticed a big → huge → gargantuan problem: Screen is dimming and the whole phone is falling asleep after some time.
As you probably figure it out by yourselves by now.
A Timer app that shows you time counter that falls asleep after couple of seconds and needs user interaction during exercises kinda misses a point (at least for other people who need an app like this and would want to download mine)…

So here are my two questions I really hope someone could help me with:

Is there any way to implement WAKE LOCK permission inside (javascript extension or something) or outside (i.e. Android Studio) of GDevelop?
Could you kindly provide me with necessary information so I could do it myself?

PS: I tried to implement the permission myself but I failed every time so I gave up and now I’m asking for your kind help :slight_smile:

1 Like

To Implement:

  1. Create a JS event that will be called a single time
  2. Add this:
window.powerManagement.acquire(function() {
	console.log('Wakelock acquired');
}, function() {
	console.log('Failed to acquire wakelock');
});

To Build:

  1. Install cordova cli
  2. Export as manual build for cordova
  3. Go with cmd to exported directory
  4. Type 'cordova plugin add https://github.com/Viras-/cordova-plugin-powermanagement.git
  5. Build with online phonegap build or cordova cli
1 Like

Thank you! I’ll try it as soon as I can.

1 Like

oh my gosh…

is there no easier way to keep the display on :exploding_head: :cold_sweat: :scream:

In every step of your exemple, i have an issue somewhere.
isn´t someone in the mood to write an extension?

what about to trick the system with a kind of “simulating touch” every 10 (or what) seconds?
Is there a way to make simulated touches?

No, this is the only way for now. And extensions with Cordova plugins are really annoying to make.

hi arthuro555

thanks for replay.

i’m a absolutely beginner in that issue, i know it´s a really hard work to explain the steps in a more detailed way (really a “oh nooooo not again dude” thing :roll_eyes: :sweat:), but maybe you are in the mood to show a more detailed way? Please? i mean… please? really please? :sweat_smile:

Point 1 and 2 is clear, but i don´t get this points:

  1. Go with cmd to exported directory
  2. Type 'cordova plugin add https://github.com/Viras-/cordova-plugin-powermanagement.git
  3. Build with online phonegap build or cordova cli

3 = where do i go where? i mean, how do i “go” with cmd to the exported directory?

4 = where do i type this?

5 = i´ve loaded phonegap, but it doesn´t start anyhow, just the loading image all over the time, so i would use the cordova cli, but what i have to type there?

Please mate, help me up (and my unknowing fellows after me)
thank you in before :+1::+1::+1::+1:

For the build:

  1. Install node Js
  2. Open the command line and type npm i --global cordova
  3. Change the directory if the command line to your GDevelop installation directory (changing directory in command line is with cd, Google that if you don’t know how to use it)
  4. Change directory to resources\GDJS\Runtime\Cordova
  5. Enter the command cordova plugin add [https://github.com/Viras-/cordova-plugin-powermanagement.git](https://github.com/Viras-/cordova-plugin-powermanagement.git) in the command line
  6. Build normally from GDevelop.

hi and thank you very much

but how should it be different, it doesn´t work, here my steps:

i´ve downloaded node.js = check

i opened the cmd and and typed npm i --global cordova.
so far so good, this is what i get:

now i´ve changed the directory as you described:
erkl2
erkl3

correct way?

now one can see new elements in the directory:

now i´ve tried to pack an app vie GDevelop as usual, but now i get an error
:

in the log file are only “ERROR” nothing more
i´ve tried again without the java code in my app, same result:

With the code:

and without:

:man_shrugging:

What did i wrong?

meanwhile i did it (partly at least) with your first description.

This “cd” thing in cmd was the key, i didn´t understand what has been the meaning of “Go with cmd to exported directory” now i got it.

And i´ve uploaded the for cordova exported files to phonegap and i was able to download my app.
But the app doesn´t work, it freez, maybe i did something wrong in your description “Create a JS event that will be called a single time”?

I am not sure what you did wrong, everything seem right. Sorry, I can’t help you further.

Ok thank you, i’ll keep on trying🤙

Viel Glück! :slightly_smiling_face:

Hello. If the app freezes during the loading (at 100%) check if it’s because of the JS script you’ve added (remove it and check if the app exports correctly and works). For me my app worked perfectly as long as there was no JS script in the events. If that’s the case then you may want to export the game manually once again and then in cmd do this (after you have installed the gihub addon - git smc: Git - Downloads):

  1. Go to the exported directory of the exported project with cmd.
  2. Then type: cordova plugin add https://github.com/Viras-/cordova-plugin-powermanagement.git
  3. Wait until the plugin gets added to the directory and your project
  4. After that in the same window type: cordova platform add android
  5. Wait until it gets finished and then type: cordova build android
  6. After that go to the directory shown in the cmd window (there should be a prompt that cordova successfully build android apk and saved it in a {} directory) everything should work

Hopefully that helps :slight_smile: .

PS: you may want to type: “npm i -g cordova” to update it to the newest version.
Plus check what type of Java you have installed on your PC, If it’s JDK 1.8. (not JRE) then you’re good. If it’s JDK 9, 10, 14 or something new then for some reason it won’t work.
Plus make sure you have Android Studio IDE installed (preferably build 173, it automatically installs Android SDK and Gradles which are required to build android via cordova)

1 Like

Danke Danke :grin:

i didn´t get it till now, i worked with clickteam again because for this app i need a WakeLock

1 Like

Hi :raised_hand_with_fingers_splayed:

yea wonderful, i´ll try it as soon as possible, i let you know about my results

Tahnk you very much :hugs:

YEAAHHHH IT WORKS!

Thank you very muyh Darious and Arthuro555 :star_struck:

Of course i had exactly that problem you descriped (Problems with JDK a.s.o.)
After many installations, De-installations, Re-installations, i´ve found out that i hav to set the enviroment for JDK and Gradle.
I had several JDK Versions, so i deleted all of them but JDK 8. (1.8_XXX)
further i´ve found good sites where you get good explainments how to set the enviroment:

For Gradle i found this
Video

and for setting the JDK envirmonet:

(sorry, only in german)

But after fixing that, it worked as you descriped - thank you very much again :+1:

nevertheless, i hope there will be easier ways to handle such things in future :blush:

1 Like

I’m glad it worked :slight_smile:. Now you’re one step further towards the release. Once you get a hang on the manual export and then cmd you can open the exported project files in Android studio and, for example, change the color of your Splashscreen background (pretty simple to do) and more (pretty hard to do :wink:).

well i have another issue… :tired_face:

I´ve tried to upload my apk, but Google Play prompt me an error because of debugable App.
I have to set debuggable to “false”.
I´ve try to change in android studio, but the file is readable only.
Where do i change this?

regards
Mario Michel