Android Question BroadCastReceiver to know VOLUME_UP or VOLUME_DOWN is pressed

Albert Lin

Member
Licensed User
Longtime User
Dear All

I use BroadCastReceiver to detect KEYCODE_VOLUME_UP or KEYCODE_VOLUME_UP pressed
the code is as following. but how to know which key is pressed? Is KEYCODE_VOLUME_UP or KEYCODE_VOLUME_UP?

Best Regards
Albert Lin

B4X:
Sub Service_Create
    Broadcast.Initialize("BR")
   
End Sub

Sub Service_Start (StartingIntent As Intent)
    Broadcast.SetPriority(2147483647)   
    Broadcast.registerReceiver("android.media.VOLUME_CHANGED_ACTION")
       
End Sub

Sub Service_Destroy
    Broadcast.unregisterReceiver
End Sub
Sub BR_OnReceive(Action As String, Extras As Object)
   
    gVibrate.Vibrate (190)
    CallSubDelayed(Main, "btnSave_Click")
    ToastMessageShow(Action,False)
    
End Sub
 
Top