Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am getting all Attached Device List.. with ID
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
deviceInfoModels.clear();
while (deviceIterator.hasNext()) {
UsbDevice device = deviceIterator.next();
DeviceInfoModel deviceInfoModel = new DeviceInfoModel();
deviceInfoModel.setDeviceClass(device.getClass() + "");
deviceInfoModel.setDeviceID(device.getDeviceId()+"");
deviceInfoModel.setDeviceName(device.getDeviceName() + " " + device.getProductName());
deviceInfoModel.setVendorID(device.getVendorId() + "");
deviceInfoModel.setDeviceSubClass(device.getDeviceSubclass() + "");
deviceInfoModel.setProductID(device.getProductId() + "");
deviceInfoModels.add(deviceInfoModel);
**This Code For Input Device**
InputManager inputManager = (InputManager) getSystemService(Context.INPUT_SERVICE);
for (int i = 0; i < inputManager.getInputDeviceIds().length; i++) {
InputDevice inputDevice=inputManager.getInputDevice(inputManager.getInputDeviceIds()[i]);
inputDevice.getVendorId();
inputDevice.getId();
when i match InputDevice ID and UsbDevice Id i get different IDs.
Note : I get all the correct information, like product name,vendor id etc.
But My issue is i have multiple Mouse attached with my board.
i can not get which mouse was clicked.
My Code for Mouse Clicked
@Override
public boolean onTouchEvent(MotionEvent event) {
// Mouse input is treated differently:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
InputDevice.SOURCE_MOUSE == InputDevice.SOURCE_MOUSE) {
Toast.makeText(this, event.getDeviceId() + "", Toast.LENGTH_LONG).show();
return super.onTouchEvent(event);
I get Device id Different HERE.
HOW CAN I GET WHICH MOUSE WAS CLICKED
Use InputDevice Instead of USBDevice and you will get same id..
InputManager inputManager = (InputManager) getSystemService(Context.INPUT_SERVICE);
for (int i = 0; i < inputManager.getInputDeviceIds().length; i++) {
if (InputDevice.SOURCE_MOUSE == inputManager.getInputDevice(inputManager.getInputDeviceIds()[i]).getSources()) {
InputDevice inputDevice = inputManager.getInputDevice(inputManager.getInputDeviceIds()[i]);
DeviceInfoModel deviceInfoModel = new DeviceInfoModel();
deviceInfoModel.setDeviceClass(inputDevice.getClass() + "");
deviceInfoModel.setDeviceName(inputDevice.getName() + " " + inputDevice.getProductId());
deviceInfoModel.setVendorID(inputDevice.getVendorId() + "");
deviceInfoModel.setDeviceID(inputDevice.getId() + "");
// deviceInfoModel.setDeviceSubClass(inputDevice.isEnabled() + "");
deviceInfoModel.setProductID(inputDevice.getProductId() + "");
deviceInfoModels.add(deviceInfoModel);
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.