I have develop a audio recorder which is working perfectly in foreground as well as background.But there is a problem when i am running audio recorder in background and start another app which used the sound(like video recorder, music player, video player etc) so the app will crash. So i want to add a functionality in audio recorder that when the other app (like video recorder, music player, video player etc) which are using microphone or speaker are running in foreground so audio recorder automatically go to the pause state.Thank in advance.
If u are still not understand my problem so please used your mobile and play the music player than go to the home. So the music player is running.And open the another app which are not using mic & speaker so music player is still running but when u r open another app which are using mic & speaker(like video recorder, music player, video player etc) so music player will pause. This type functionality i wanted.Thanx in advance
Finally lot of search & googling i have got the answer of this question. I am using audiofocuschangelistener. The code is there
AudioManager.OnAudioFocusChangeListener audioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() { public void onAudioFocusChange(int focusChange) { switch(focusChange) { case AudioManager.AUDIOFOCUS_GAIN: case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT: case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK: //resume your activity break; case AudioManager.AUDIOFOCUS_LOSS: case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: ///pause your activity break; } } };and do this in onCreate()
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int result = audioManager.requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { //start your activity }And for more information u can follow below link
http://developer.android.com/training/managing-audio/audio-focus.html