Prevent Android Chrome Launch in Standby / Auto Lock / Sleep Phone?

I need to make some kind of function of a disabled inactivity / sleep phone on a website. Is anyone trying to do this on an Android phone? is it possible?

+4
source share
3 answers

We strongly do not encourage developers to do this at all. However, this is possible. You can simply play the video on the page and the device will not sleep. This means that you may have a single-frame video configured to automatically cycle and play (user interaction required)

NoSleep.js, .

+4

API Wake Lock (http://www.w3.org/TR/wake-lock/) Chromium, 48.0.2551.0. , , . --enable-experimental-web-platform-features , . , , .

+1

JavaScript Chrome Android (7.0) 5 . Aaargh!

, , , :

<audio id="dummyAudio">
   <source src="silent.ogg" type="audio/ogg">
   <source src="silent.mp3" type="audio/mpeg">
</audio>

:

function playDummyAudio() { dummyAudio.play(); }    
$(function() {
   var dummyAudio = document.querySelector('#dummyAudio');
   window.addEventListener(playDummyAudio, 60 * 1000);
}

Note that the audio object must be “unlocked” in the user gesture callback. This can be accomplished, for example, using a gray CSS overlay with a large thick dummy Start button, whose callback onClick()only hides the overlay and calls dummyAudio.load().

0
source

Source: https://habr.com/ru/post/1617570/


All Articles