Android Question Consume volume button and prevent volume change

Beja

Expert
Licensed User
Longtime User
Hi,
I am working on alarm system, and don't want the user to disable or lower the volume. A lot of useful information is on the forum, but didn't find any of them specific to what I need. To set the volume to maximum and prevent the user from changing it.
Code example, please!

thanks in advance.
 

derez

Expert
Licensed User
Longtime User
You can use this:

To set the volume to max -
SetVolume (Channel As Int, VolumeIndex As Int, ShowUI As Boolean)
Sets the volume of the specified channel.
Channel - One of the VOLUME constants.
VolumeIndex - The volume index. GetMaxVolume can be used to find the largest possible value.
ShowUI - Whether to show the volume UI windows.
Example:
Dim p As Phone
p.SetVolume(p.VOLUME_MUSIC, 3, True)

to inhibit volume down -

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then ....
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
You can use this:

To set the volume to max -


to inhibit volume down -

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then ....
Is it just to avoid a false manipulation? Because, in any other case, the user will just have to switch to another application or press Home before changing the volume.
 
Upvote 0
Top