Попробуйте этот более простой код, я проверял это ...
(полный код здесь http://blog.kerul.net/2012/01/how-to-pause-audio-while-call-is.html)
public class UrClassActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
private MediaPlayer mp;
...
...
...
//this is a code segmentation
//THis two lines of codes need to be inserted to the onCreate method
//This following codes dealing with the phone-state
//detect voice incoming call
//onCallStateChanged method will be executed if there's incoming
//or outcoming call
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
//INCOMING call
//do all necessary action to pause the audio
if(mp!=null){//check mp
setPlayerButton(true, false, true);
if(mp.isPlaying()){
mp.pause();
}
}
} else if(state == TelephonyManager.CALL_STATE_IDLE) {
//Not IN CALL
//do anything if the phone-state is idle
} else if(state == TelephonyManager.CALL_STATE_OFFHOOK) {
//A call is dialing, active or on hold
//do all necessary action to pause the audio
//do something here
if(mp!=null){//check mp
setPlayerButton(true, false, true);
if(mp.isPlaying()){
mp.pause();
}
}
}
super.onCallStateChanged(state, incomingNumber);
}
};//end PhoneStateListener
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if(mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
...
...
...
}//end onCreate
}//end class