Reputation: 11590
I am writing a Xamarin app and have successfully deployed it to my Fire TV hardware; however, when I try to use the amazon remote my app is not responding, since the hardware does not support Tap Gestures, which makes sense.
What I have tried
After following the link on this page, it appears that there was a Fire TV Component, but when I click on the link, it turns out the component has been removed.
I found this link, but it suggests a round about work around to use the deprecated component, by ripping it out from some other random project, which is not ideal.
I saw mention that the preferred way is to use a Nuget package; however, after a bit of searching, I have yet to find any packages that seem to match what I am looking for.
I also saw mention that the latest Fire OS prefers use of the Google apis instead of custom Amazon ones, which makes me think there is a "Xamarin Google Game Input" type of nuget package out there somewhere that might work, but have had no luck in finding.
As a potential alternative to using a Nuget package that may or may not exist, I thought about manually handling keyboard input and mapping using this table that maps a button on the Amazon remote to a keyboard code, but I am unsure how to implement this for Android (Xamarin) as all the examples I have found are for Windows.
Further details
The current UI is pretty simple, tap the screen to pull up a menu, then select one of three buttons. I image translating that for the Amazon remote would be: Press the Select button (Middle circle), then us the directional pad to select one of the three buttons, then press the Select button.
I anticipate also needing to add support for the back button, which fingers crossed should come naturally once the other input needs are met.
So in summary, my question is:
For my Xamarin Android App, how can I add support for the stock Amazon remote that comes with the Fire TV hardware?
Upvotes: 0
Views: 974
Reputation: 11590
To manually add support, here is a summary of the main points to get it working.
Disclaimer, this is untested code.
using Xamarin.Forms;
public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
{
//Use Xamarin's event system to send the event.
MessagingCenter.Send<MyCustomPage, int>(this, "KeyUp", (int)keyCode);
return base.OnKeyDown(keyCode, e);
}
*.xaml.cs
using Xamarin.Forms;
public void OnAppearing()
{
MessagingCenter.Subscribe<MyCustomPage, int>(this, "KeyUp", async (sender, KeyCodeArg) =>
{
await TheUserGaveInput(KeyCodeArg); // do whatever you need
});
}
public void OnDisappearing()
{
MessagingCenter.Unsubscribe<MyCustomPage, int>(this, "KeyUp");
}
ProcessUserInput()
method.Example handing for a specific page:
public override async Task TheUserGaveInput(int keyCode)
{
if(keyCode == (int)MyKnownKeyCodes.PlayPause_FireOS ) {
// Do something, like toggle play or pause for a video
}
}
MyKnownKeyCodes
in the example above.For specific Fire OS input:
// Button name = keycode
DpadUp_FireOS = 38,
DpadDown_FireOS = 40,
DpadLeft_FireOS = 37,
DpadRight_FireOS = 39,
PlayPause_FireOS = 179,
FastForward_FireOS = 228,
Rewind_FireOS = 227,
SelectDPadCenter_FireOS = 13,
To support all the other devices:
DpadUp = 19,
DpadDown = 20,
DpadLeft = 21,
DpadRight = 22,
Enter = 66,
Space = 62,
PlayPause = 85,
Rewind = 89,
SelectDpadCenter = 23,
You can also read more about Xamarin's MessageCenter for clarity.
Upvotes: 2