Java tutorial
//package com.java2s; //License from project: Apache License import android.view.InputDevice; public class Main { public static int getConnectedInputDevices() { int[] deviceIDs = InputDevice.getDeviceIds(); int result = 0; for (int i = 0; i < deviceIDs.length; i++) { InputDevice dev = InputDevice.getDevice(deviceIDs[i]); /*if (dev.isVirtual()) continue;*/ int sources = dev.getSources(); if ((sources & InputDevice.SOURCE_CLASS_BUTTON) != 0) result++; } return result; } }