Android Question BroadCastReceiver to know VOLUME_UP or VOLUME_DOWN is pressed

Discussion in 'Android Questions' started by Albert Lin, Oct 15, 2016.

  1. Albert Lin

    Albert Lin Member Licensed 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

    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Note that it is better to register it in Service_Create. Service_Start can be called multiple times.

    What is the output of Log(Extras)?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice