3

How can I differentiate between a TV and a STB/game console on AndroidTV programatically? This method (https://developer.android.com/training/tv/start/hardware) won't work because an STB running AndroidTV is considered a television.

Poka Yoke
  • 373
  • 3
  • 8
  • 27

1 Answers1

0

What's Your Goal?

The obvious reason for doing this would be to determine if a device is suitable for a game to be played on. If it's for any other reason, then the purpose needs to be elaborated on in order to receive applicable assistance.

With that said ...

Since it's not possible to query the device type directly -- personally, I'd look for something that only a game console would be likely to have.
In other words: a game controller/gamepad.

public ArrayList<Integer> getGameControllerIds() {
    ArrayList<Integer> gameControllerDeviceIds = new ArrayList<Integer>();
    int[] deviceIds = InputDevice.getDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = InputDevice.getDevice(deviceId);
        int sources = dev.getSources();

        // Verify that the device has gamepad buttons, control sticks, or both.
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
                || ((sources & InputDevice.SOURCE_JOYSTICK)
                == InputDevice.SOURCE_JOYSTICK)) {
            // This device is a game controller. Store its device ID.
            if (!gameControllerDeviceIds.contains(deviceId)) {
                gameControllerDeviceIds.add(deviceId);
            }
        }
    }
    return gameControllerDeviceIds;
}

Of course, it's not fool-proof. Obviously, nothing would be returned if the gamepad(s) were unplugged at the time (not sure when that would happen). Not to mention, some TVs support gamepads (Samsung comes to mind first) -- but, if you're intention is to verify that there's an adequate input available for the application, this would be ideal.

If a gamepad isn't present, a message could be displayed stating, "Please connect a gamepad." -- while continuously checking in the background, and automatically proceeding once one is detected.

Dustin Halstead
  • 741
  • 6
  • 19
  • For my case, a Set-Top-Box is equally important to a game console, and although your answer somehow tackles the problem but in my case it would only solve 20% of the cases. – Poka Yoke May 22 '18 at 23:05
  • @PokaYoke -- So the question is: What's the reason for differentiating the device type? ... Knowing that would greatly assist towards helping identifying a solution. – Dustin Halstead May 23 '18 at 17:50
  • I can't say why exactly, but I want a solution that would differentiate between TVs and connected devices (STBs/Game Consoles). The solution should work for most cases (80% of the cases at least). – Poka Yoke May 25 '18 at 19:53
  • Differentiating between devices is usually based on use-case scenarios (display size, rendering ability, etc.). Since there's no way to request the device type, without knowing the specific feature you're targeting, I'm afraid there's not much help that can be offered. I say this with all certainty because I develop applications for SmartTVs. Information can't be requested from them unless the TV's API is loaded first, and then making the request that's specific to that particular brand (LG, Samsung, etc.) Your only option is to look for connected hardware that's not dependent on the OS. – Dustin Halstead Jun 05 '18 at 13:00
  • Just wanted to ask if you could please accept my answer. I'm sorry that there's no way to currently differentiate between Android devices that lean more towards gaming or TV. Android is just an OS. ... Determining the primary intent of an Android device is no different than trying to determine if a Windows machine is being used for gaming or productivity. Detecting a game controller is likely your best option. ... I know it's not the answer you'd like, but it would still be polite if you could please accept my answer. – Dustin Halstead Jul 05 '18 at 15:12