rops
rops

Reputation: 217

Detecting inactivity in fennec - firefox mobile extension

I'm building an addon for firefox mobile (fennec). Is it possible to detect if the browser is running in background or the screen is locked so that I can suspend some task that is running within my extension?

Upvotes: 0

Views: 90

Answers (2)

Mark Finkle
Mark Finkle

Reputation: 966

You can also listen for the "application-foreground" and "application-background" notifications. Firefox does this itself here:

http://mxr.mozilla.org/mozilla-central/source/mobile/android/chrome/content/browser.js#5445

Upvotes: 1

Wladimir Palant
Wladimir Palant

Reputation: 57651

I don't think that you can - Fennec itself doesn't seem to care whether the screen is on or off, at least I couldn't find any code checking that. Normally I would recommend js-ctypes to call the necessary OS functionality directly but it is of very limited use on Android. So I guess that the best thing you can do is using nsIIdleService to detect when the user has been inactive for a while.

Upvotes: 0

Related Questions