Android Question Building app to be accessible to Fire TV controller

Discussion in 'Android Questions' started by Scotter, Jan 4, 2019.

  1. Scotter

    Scotter Active Member Licensed User

    I have a friend who's only Android device is an Amazon Fire TV.
    My app scales well to it.
    BUT he said his controller doesn't work well with it.
    Does anyone have advice on how I can make the app work better with his Fire TV controller?
    Thanks!
     
  2. moster67

    moster67 Expert Licensed User

    Check the "input event reference guides" of the Fire TV remote control and its game controller:

    https://developer.amazon.com/it/docs/fire-tv/remote-input.html#input-event-reference
    https://developer.amazon.com/it/docs/fire-tv/game-controller-input.html#inputreference

    Normally, the basic input events are standard among all remote- and game-controllers independent of make/model.

    Then using the Activity_KeyPress event, get the KeyCode and do something with your code. Perhaps something like this:

    Code:
    Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
        
        
    Select KeyCode
            
    Case KeyCodes.KEYCODE_DPAD_LEFT
                
    Log("DPAD_LEFT")
            
    Case KeyCodes.KEYCODE_DPAD_RIGHT
                
    Log("DPAD_RIGHT")
            
    Case KeyCodes.KEYCODE_DPAD_DOWN
                
    Log("DPAD_DOWN")
            
    Case KeyCodes.KEYCODE_DPAD_UP
                
    Log("DPAD_UP")
            
    Case KeyCodes.KEYCODE_ENTER
                
    Log("DPAD_ENTER/CENTER")
     
            
    Case Else
                
    Log(KeyCode)
        
    End Select

    Return False
     
    End Sub
    This may also be helpful:
    https://www.b4x.com/android/help/constants.html#keycodes
     
    Last edited: Jan 5, 2019
    Scotter likes this.
  3. Scotter

    Scotter Active Member Licensed User

    Wow, Monster, that is a wealth of information and you even gave me code examples!
    Much appreciation for your generosity!
     
  4. Scotter

    Scotter Active Member Licensed User

    OK I'm getting sporadic behavior with logging my key presses on the d-pad (and tab and enter buttons) on my Android keyboard.
    Like sometimes it logs D-pad-left, right, etc. but most of the time not.
    Having a hard time isolating why.
    Here's your code slightly modified:
    Code:
    'FOR FIRE TV
    Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
        Select KeyCode
            
    Case KeyCodes.KEYCODE_DPAD_LEFT
                
    Log("DPAD_LEFT")
                
    'Tab_Prev will go in this spot
            Case KeyCodes.KEYCODE_BACK
                
    Log("KEYCODE_BACK"'remote controller
                'Tab_Prev will go in this spot
            Case KeyCodes.KEYCODE_MEDIA_REWIND
                
    Log("KEYCODE_MEDIA_REWIND"'remote controller
                'Tab_Prev will go in this spot   
            Case KeyCodes.KEYCODE_DPAD_RIGHT
                
    Log("DPAD_RIGHT")
                Tab_Next 
    'never gets called :-(
                'Do I want to consume the event?
                'Return True           
            Case KeyCodes.KEYCODE_MEDIA_FAST_FORWARD
                
    Log("KEYCODE_MEDIA_FAST_FORWARD"'remote controller
                Tab_Next 'never gets called :-(
                'Do I want to consume the event?
                'Return True
            Case KeyCodes.KEYCODE_DPAD_DOWN
                
    Log("DPAD_DOWN")
            
    Case KeyCodes.KEYCODE_DPAD_UP
                
    Log("DPAD_UP")
            
    Case KeyCodes.KEYCODE_ENTER
                
    Log("DPAD_ENTER/CENTER")
            
    Case Else
                
    Log("activity_keypress=" & KeyCode)
                
    'this firing SOMETIMES
        End Select
    End Sub
    Ideas?
     
  5. moster67

    moster67 Expert Licensed User

    I did this ages ago (5-6 years ago) and I probably don't even have the code any longer so I doubt I can be on any further help.

    However, you could test with the Android emulator. If I recall correctly, you can enable the directional pads and use them. Just to make sure it is not the android keyboard creating any problems. Best would be to send over a test app to your friend with the Fire TV and see how it behaves.

    Not sure what your issues are. Timing? Try to insert "Return false" at the end of the code-snippet I posted (I modified it so you can see where). Search the forum for other examples using keycodes. Herre is another one:
    https://www.b4x.com/android/forum/t...-or-down-on-remote-control.66147/#post-422274

    Good luck.
     
    Last edited: Jan 5, 2019
    Scotter likes this.
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