Android Question Handling Volume Keys on Android

pbsys

Member
Licensed User
Hi there,

Is there a way to control the volume keys of an android device using b4A ??
thks in advance.
pb
 
If your activity is in the foregound then you can handle them with Activity_KeyUp event.
Thanks Erel that could help...just another question related to this topic...If I am in the foreground is there any way to emulate let say the "click" of this button ?? I meant, letting believe to the Android OS that this action was performed like somebody has clicked the real button ??
 
Upvote 0
If I am in the foreground is there any way to emulate let say the "click" of this button ?
you just can call the event sub....

You can not control OTHER Apps.
 
Upvote 0
you just can call the event sub....

You can not control OTHER Apps.
Thank you Manfred for your quick response and my apologize for asking this, but I am new with this language and is taking a while...but what do you mean with calling the "event sub", can you give me a clue ??

Once again, thanks for the help provided.
pb
 
Upvote 0
Hi pb,
this time I'll be faster than Manfred..ehehe
With "calling the event sub" he suggested to do something like this:
Code: Copy
Sub Button1_Click
...
end sub
..
'In your code, when you need to simulate Button1 click just insert

Button1_click
 
Upvote 0
Hi,
This is to Increase and Decrease of the Media volume value.

B4X: Copy
Sub Activity_KeyPress (KeyCode As Int) As Boolean

    Dim PhoneVolume As Phone

    If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then
        If PhoneVolume.GetVolume(PhoneVolume.VOLUME_MUSIC) > 0 Then
            PhoneVolume.SetVolume(PhoneVolume.VOLUME_MUSIC,PhoneVolume.GetVolume(PhoneVolume.VOLUME_MUSIC)-1,True)
        End If   
    End If
    If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
        If PhoneVolume.GetVolume(PhoneVolume.VOLUME_MUSIC) < PhoneVolume.GetMaxVolume(PhoneVolume.VOLUME_MUSIC) Then
            PhoneVolume.SetVolume(PhoneVolume.VOLUME_MUSIC,PhoneVolume.GetVolume(PhoneVolume.VOLUME_MUSIC)+1,True)
        End If
    End If
End Sub
 
Upvote 0
Back
Top