Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap detect if the phone is active

I've been searching for a while now, and can't find anything for this with Phonegap only for Android or IOS.

So would be nice if someone knew how or if its even possible. Is there a way to check if the phone is in use/active, or if the phone is inactive/screen locked etc.?

Thanks

like image 359
Marius Djerv Avatar asked Aug 11 '14 07:08

Marius Djerv


1 Answers

Yes, you can accomplish this by using two of the built-in phonegap events:

  • pause - this event is triggered once the application is put in the background (i.e. when it's not active)

Example:

document.addEventListener("pause", yourCallbackFunction, false);
  • resume - and this one is triggered when the application is invoked back into the foreground (i.e. becomes active)

An example would be:

document.addEventListener("resume", onResume, false);

function onResume() {
  // Handle the resume event
}

Hope that helps!

like image 105
pstoev Avatar answered Nov 03 '22 11:11

pstoev