Disable Volume Toast

JonPM

Well-Known Member
Licensed User
Longtime User
Hey all, I am looking for a way to disable the volume toast that appears with the user adjusts volume using the hardware keys (AKA the volume seek bar). It appears possible from this post on StackOverflow, and I'm wondering if I can use reflector to perform this in B4A? If so, can someone help with the code?

The code:
B4X:
AudioManager manager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);
 

JonPM

Well-Known Member
Licensed User
Longtime User
This code allows you to set the volume programmatically without showing the UI. It is equivalent to using Phone.SetVolume.

You can try to intercept the key presses and handle the volume yourself.

The problem I'm having is that Phone.SetVolume still shows the UI even when set to False. I am using a Samsung Galaxy Tab 2 on 4.0.4 and HTC Rezound on 4.0.3.

Below is my code:

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 
   If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then
         If p.GetVolume(p.VOLUME_SYSTEM) > 0 Then
            p.SetVolume(p.VOLUME_SYSTEM, p.GetVolume(p.VOLUME_SYSTEM) - 1, False)
        End If
      
    End If
    
    If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
        If p.GetVolume(p.VOLUME_SYSTEM) < p.GetMaxVolume(p.VOLUME_SYSTEM) Then
            p.SetVolume(p.VOLUME_SYSTEM, p.GetVolume(p.VOLUME_SYSTEM) + 1, False)
        End If    
    End If
End Sub
 
Last edited:
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
In the chatroom tds pointed out that I need to Return True in each event. That did the trick!
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
In the chatroom tds pointed out that I need to Return True in each event. That did the trick!

Yes, the keystroke has to be consumed.

From curiosity, is there a specific reason for hiding the volume toast?
 
Upvote 0
Top