How to access standard input from android app?

前端 未结 1 1747
[愿得一人]
[愿得一人] 2021-01-23 11:39

I\'m using a magnetic strip reader that seems to output to the standard input. When I plug it into my android device, open up a notepad app, and swipe, it\'ll automatically past

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-23 11:44

    No this would not be working by means of standard input. That is not meaningful for Android applications (stdin, stdout, and stderr exist, but are normally unused).

    Rather, Android has it's own input processing structure, see for example:

    https://source.android.com/devices/input/overview.html

    Chances are that your reader is a USB HID device which android is treating a something akin to a physical keyboard, and handling the input characters as if they were key events typed on such.

    Normal Android app input handling methods (key events, input to focused text fields, etc) will capture this fine when your app is in the foreground. When it is not, you may not be able to reserve the input for your app, unless you can modify the Android installation, or alter your device to be a custom non-HID peripheral.

    0 讨论(0)
提交回复
热议问题