src/com/android/providers/media/RingtonePickerActivity.java
//added start
private AudioManager mAudioManager = null;
private boolean mGetFocus = false;
//added end
setupAlert();
mAudioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);//added
if (ringtone.getUri() != null) ringtone.play();
//added start
int result=mAudioManager.requestAudioFocus(mAudioFocusListener,
AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
mGetFocus = false;
} else {
mGetFocus = true;
}
//added end
if (mRingtoneManager != null) {
mRingtoneManager.stopPreviousRingtone();
}
//added start
if (mGetFocus && (null != mAudioManager)) {
if (AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.abandonAudioFocus(mAudioFocusListener)) {
mGetFocus = false;
} else {
mGetFocus = true;
}
}
//added end
//added start
private OnAudioFocusChangeListener mAudioFocusListener = new OnAudioFocusChangeListener() {
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_LOSS:
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
stopAnyPlayingRingtone();
break;
}
}
};
//added end