Kamala Phoenix
Kamala Phoenix

Reputation: 127

How to access standard input from android app?

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 paste a string to the app as if I had typed it. (Hence why I think it's outputting to the standard IO). I want to read the data programatically. How do I access the standard IO for android?

I've tried making a Scanner from System.in as well as an InputStream from System.in but I'm not getting any results.

Upvotes: 1

Views: 1425

Answers (1)

Chris Stratton
Chris Stratton

Reputation: 40397

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.

Upvotes: 1

Related Questions