Wake Lock screen permission for Android mobile devices


#1

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?

https://developer.android.com/reference/android/Manifest.permission.html#WAKE_LOCK

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:


#2

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

#3

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