I’d like to play a sound from a (ringtone) URI in my Android application. However, I would like to play this sound at an arbitrary volume and not have system volumes, such as Media and Ringtone volume, affect playback.
I’ve been paging through the API docs, but I’m at a loss. Is this possible with Android and if so, how would I do it?
I believe most apps aiming to do this choose a stream type, stash the current volume level (using
AudioManager.getStreamVolume), set that volume to whatever they want it to be (usingsetStreamVolume()to some percentage ofgetStreamMaxVolume), and then restore the stashed volume level after playback completes. But think hard before you do this — unless you’re creating a “find my lost phone” app, there’s rarely a reason to ignore the user’s requested volume levels, and you run a high risk of irritating someone silencing their phone for a meeting.