Device.setSystemVolume()
Overview
Sets the volume for an audio stream on the Android device. This affects volume for all applications.
Added in version 2.1.38
Android only
Remarks
To only change the beep volume, use Device.setBeepVolume() instead. If the device has Do Not Disturb turned on, this API may be ineffective.
Format
Device.setSystemVolume(volume, stream);
Parameter | Description | Type | Required | Notes |
---|---|---|---|---|
volume | Volume to set the audio stream to. | Number | Required | Number between 0.0 (quietest) and 1.0 (loudest). Not all streams allow you to turn the volume off. For those streams, setting the volume to 0 will set it as low as the system allows. |
stream | Specifies the audio stream whose volume will be adjusted. | String | Required | The audio stream to set the volume for. Accepted values are listed in the table below. |
Audio stream
Stream | Use |
---|---|
"music" | Used for music playback and other media sounds. |
"voice_call" | Used for voice calls and wired headsets. |
"bluetooth_sco" | Used for Bluetooth headset sound. |
"system" | Used for system sounds, like low battery or errors. |
"ring" | Used for the ringtone and other alert sounds. |
"alarm" | Used for alarms, timers, and clock sounds. |
"notification" | Used for app notification sounds. |
"accessibility" | Used for accessibility features like screen readers. |
Example
Copy
/* Set the music stream volume to 50% of the maximum volume.
*/
Device.setSystemVolume(0.5, "music");