Marius Djerv
Marius Djerv

Reputation: 265

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

Upvotes: 8

Views: 2679

Answers (1)

pstoev
pstoev

Reputation: 116

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!

Upvotes: 5

Related Questions