I am trying to play a notification tone using Ringtone
class in android, my code is as below :
Uri toneUri = Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.start_sound);
Ringtone r = RingtoneManager.getRingtone(this, toneUri);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.build();
try {
r.setAudioAttributes(audioAttributes);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
The tone plays but plays on headphone not on phone speakers, a case where user is away from phone and have plugged in headphone he can't here the notification tone. I want to play it using phone speakers. What is other way of doing it any hint ?