Android: Get default or currently set alarm sound/tone?
Asked Answered
I

1

7

I searched with many terms and sentencing but could not find any information on this whatsoever. So anyways: How can I get default or currently set music/tone/sound for Alarm (Default app) ?

Say if I wake up every morning with alarm song playing: Song#1 using default alarm app, how can I get that Song#1 in my custom app?

I am trying to create my own alarm app but I don't want to set a tone that user may not like.

Perhaps there is a way to open default alarm tone picker/browser and let user set it in my custom app? Or does all of that need to be custom coded?

If none of above is possible - How can I just get default alarm sound to play in my app?

Isabea answered 15/7, 2014 at 19:38 Comment(0)
S
13
Uri alarmTone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
Ringtone ringtoneAlarm = RingtoneManager.getRingtone(getApplicationContext(), alarmTone);
ringtoneAlarm.play();
Sarcocarp answered 15/7, 2014 at 19:45 Comment(3)
Thanks, that did exactly what I wanted. I also added: ringtoneAlarm.setStreamType(AudioManager.STREAM_ALARM); that made it play alarm even in silent mode.Isabea
Sorry side question: How would I go about stopping that sound from playing from different activity?Isabea
@Isabea You just need to hold onto your ringtoneAlarm from the activity that created it (either by passing it to your next activity, or globally somewhere) and then call stop() on it. It might be a good idea to call stop from your life-cycle onPause() based on intentions.Sarcocarp

© 2022 - 2024 — McMap. All rights reserved.