Possible Duplicate:
Stopping & Starting music on incoming calls
I have a simple application that plays some audio using the MediaPlayer class. While debugging my application I found that the audio still plays during incoming and outgoing calls.
I found that the solution to my problem is using a phoneStateListener. I don’t quite understand how to do this though. I saw some examples that used a BroadcastReceiver along with the PhoneStateListener and I couldn’t understand why we needed a BroadCastReceiver.
I would appreciate it if someone could provide a sample implementation of the PhoneStateListener. If I can get the phone state I could pause or resume the audio because my MediaPlayer object is global for the entire application.
This is what I use…
The
onCallStateChanged()function gets called in all PhoneStateListeners anytime the call state has changed, so that’s what you need to handle.If you want to add this to your current Activity, do this..
Wouldn’t you rather just pause your current activity? If you pass your class an instance of the current activity, you could call finish() and create a new activity right in the switch statement if you really want to.