Can't see mouse and keyboard device with usbManager android

I work on a project where I need get data of keyboard and mouse on a service. I also have to be able to send data to my device hid. To do this, I want use the usb host mode. When I get list of device, I can see a mass storage but no mouse and keyboard. After search, I have seen that usbManager don't return mouse and keyboard device. I have tried to change permissions (on /system/etc/permissions) whitout success). I have run the application USB Device Info and I see mouse and keyboard on linux device and not on android devices.

I use android 4.2.2. Is it possible to get hid data of mouse (and keyboard) with usb host or I have to find an other way ?

Thank you for your help


You can detect mouse/keyboard via InputManager:

if(Build.VERSION.SDK_INT > 15) {
    InputManager inptmgr = (InputManager)getSystemService(INPUT_SERVICE);
    int[] inputs = inptmgr.getInputDeviceIds();
    for(int i = 0;i<inputs.length;i++) {
        String devicename = inptmgr.getInputDevice(inputs[i]).getName();
        if(devicename.toLowerCase().contains("mouse")) {

        } else if(devicename.toLowerCase().contains("keyboard")) {

        }
    }
}

As for any other data you may want to collect, you can browse all the other methods under getInputDevice() such as getVendorId() , getProductId() , getMotionRange() , getKeyCharacterMap() , and others.

Hope this helps!


If you can already use the HID device for input, it' working as a input device(keyboard or mouse) and you don't need to access it as a USB device. You can simply catch the input from the device via listeners such as OnKeyListener.

链接地址: http://www.djcxy.com/p/58316.html

上一篇: 如何在Windows上多次使用Socket地址

下一篇: 用usbManager android无法看到鼠标和键盘设备