Skip to content Skip to sidebar Skip to footer

How Can I Capture Data Coming Into My Android App From The Standard Input (stdin)?

I am writing an app that uses an external USB barcode/RFID scanner. The scanner is a standard HID, and works well on my Android devices. I plug it in, hit the scan button, and data

Solution 1:

The short answer is that you can't access stdin, there is no such animal in Android for apps. The text is being injected into the active EditText because the RFID / USB device you are using is presenting itself as a HID device. These are automatically picked up by the Android subsystem as an input source and their input routed to the active view as if it came from a keyboard.

All is not lost, however. What you can do is attach a TextWatcher to your EditText and manipulate the text in the Editable:

EditTextet= (EditText)findViewById(R.id.whatever_your_id);
et.addTextChangedListener(newTextWatcher() {
        @OverridevoidafterTextChanged(Editable s) {
            //  Make your changes to 's' here, carefully as your changes will//  cause this method to be called again!
        }

        @OverridevoidbeforeTextChanged(CharSequence s, int start, int count, int after) {
            //  Nothing to do here
        }

        @OverridevoidonTextChanged(CharSequence s, int start, int before, int count) {
            //  Nothing to do here
        }
    });

Post a Comment for "How Can I Capture Data Coming Into My Android App From The Standard Input (stdin)?"