Remigius Kijok
Remigius Kijok

Reputation: 225

Get current remote or game controller

How can I get the current input device in my application in java? I want to know is the remote or the game controller, that is being used.

It is an android application that I want to run on Amazon FireTV. Unlike the Amazon Kindle there is no touchscreen but you can use a remote or a game controller. I would like to know if it is possible to detect what kind of input device the user is currently using.

The code I have until now is a standard Cordova Application code, but when I know how to detect the current input device I would make a plugin to pass the value to the javascript code. That is not the problem.

Upvotes: 1

Views: 721

Answers (1)

Luca S.
Luca S.

Reputation: 738

As mentioned in the comments you should provide steps you have already taken or code you have already written to address this functionality as that will help us tweak the most appropriate answer. As a general rule, you can look at the official docs to identify controllers on Fire TV. https://developer.amazon.com/public/solutions/devices/fire-tv/docs/identifying-controllers

Basically, you need to write the identification code in your Cordova plugin as follows:

int hasFlags = InputDevice.SOURCE_GAMEPAD | InputDevice.SOURCE_JOYSTICK;
boolean isGamepad = inputDevice.getSources() & hasFlags == hasFlags;

This will allow you to find out if it's a gamepad. For a Fire TV remote the code you need is:

int hasFlags =  InputDevice.SOURCE_DPAD;
bool isRemote = (inputDevice.getSources() & hasFlags == hasFlags)
    && inputDevice.getKeyboardType() == InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC;

The InputDevice class is available on the Android developer site: http://developer.android.com/reference/android/view/InputDevice.html So you basically need to import that in your plugin class to ensure the above code works fine.

import  android.view.InputDevice;

Upvotes: 3

Related Questions