Can't see mouse and keyboard device with usbManager android

 ̄綄美尐妖づ 提交于 2020-01-02 10:04:13

问题


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


回答1:


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!




回答2:


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.



来源:https://stackoverflow.com/questions/26103246/cant-see-mouse-and-keyboard-device-with-usbmanager-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!