Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Use Javascript to Detect When Phonegap-based Android App Loses Focus

My title sums up my question. I have an Android App written entirely with html5 and javascript. I am a beginner at java (at best) and do not want to use java to do this, but, instead, javascript. I want to be able to turn off video and music when a phone call comes in or the application otherwise goes to the background. I have tried window.onBlur and the new html5 visibility API. No dice. Is there a way to do this without rolling up my sleeves and learning Java? I want to use javascript.

like image 973
cliffbarnes Avatar asked Nov 12 '12 12:11

cliffbarnes


1 Answers

Register for the "pause" event. When your app has been paused generally it means you've been put in the background. When you get paused stop playing the audio.

http://docs.phonegap.com/en/2.2.0/cordova_events_events.md.html#pause

Then register for a resume event and start up things again:

http://docs.phonegap.com/en/2.2.0/cordova_events_events.md.html#resume

like image 130
Simon MacDonald Avatar answered Oct 08 '22 02:10

Simon MacDonald