2

I have a web app that is accessible by Android mobile phones, and I want to vibrate the phone when a new notification comes in. I can vibrate the phone when the phone is awake, but when the phone sleeps it "freezes" the browser and the Javascript stops running.

Does anyone know of way to keep the Javascript running when an Android phone sleeps, or how to force wake it?

Taztingo
  • 1,915
  • 2
  • 27
  • 42

1 Answers1

1

Maybe you can achieve this by using wake locks:

Wake locks allow your application to control the power state of the host device.

Creating and holding wake locks can have a dramatic impact on the host device's battery life. Thus you should use wake locks only when strictly necessary and hold them for as short a time as possible.

...

One legitimate case for using a wake lock might be a background service that needs to grab a wake lock to keep the CPU running to do work while the screen is off.

EDIT

If you are using the phonegap framework, Dave Alden created a plugin for "partial wakelocks" but this was in 2013 and the plugin seems to be no longer in github, but his answer still has the code...

It would help if you mentioned the framework you are using, but I suspect you may have to deal with wake locks one way or another (if the framework abstracts their usage, the better)...

Community
  • 1
  • 1
Armfoot
  • 4,663
  • 5
  • 45
  • 60
  • This is a good answer for a normal android app. I am building a webapp/website using html and javascript. – Taztingo May 25 '15 at 18:08
  • @user1932934 Well, you mentioned Android, so I assumed you were referring to it... And my answer provided you with a possible solution (not a wrong one, therefore your downvote may keep other people to provide other solutions for you). It would be easier to provide a better answer if you mentioned the framework you are using. Their documentation may refer in someway to these wake locks or something similar... – Armfoot May 25 '15 at 18:19