1

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 ?

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Prashant
  • 4,474
  • 8
  • 34
  • 82
  • Please add comment for close suggestion if its worth I will delete my question. – Prashant Sep 22 '17 at 11:48
  • This question may be of interest https://stackoverflow.com/questions/31397934/how-to-play-audio-through-speaker-even-when-headset-is-plugged-in – aveuiller Sep 22 '17 at 12:14

0 Answers0