title: How to read data from usb device on Android?
body: <p>I have a device which I need to connect via usb to my android phone. I simply want to read some data this device is sending and present it on my app screen.
  I've tried some API's such <a href="https://github.com/felHR85/UsbSerial" rel="nofollow noreferrer">https://github.com/felHR85/UsbSerial</a> and <a href="https://github.com/mik3y/usb-serial-for-android" rel="nofollow noreferrer">https://github.com/mik3y/usb-serial-for-android</a> where I found the code below </p>
  
  <pre><code>    public class MainActivity extends AppCompatActivity {
  
      private TextView data;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          data = findViewById(R.id.data);
  
          UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
          List&lt;UsbSerialDriver&gt; availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager);
          if (availableDrivers.isEmpty()) {
              return;
          }
  
  // Open a connection to the first available driver.
          UsbSerialDriver driver = availableDrivers.get(0);
          UsbDeviceConnection connection = manager.openDevice(driver.getDevice());
          if (connection == null) {
              // You probably need to call UsbManager.requestPermission(driver.getDevice(), ..)
              return;
          }
  
  // Read some data! Most have just one port (port 0).
          UsbSerialPort port = driver.getPorts().get(0);
          try {
              port.open(connection);
              port.setParameters(57600, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
  
              byte buffer[] = new byte[8];
              int numBytesRead = port.read(buffer, 1000);
              //Log.d(TAG, "Read " + numBytesRead + " bytes.");
              data.setText(numBytesRead);
          } catch (IOException e) {
              // Deal with error.
          } finally {
              try {
                  port.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>
  
  <p>It simply does not read anything at all, is there a simpler way to do that?</p>
  
  <p>The device I'm trying to read from is an oximeter (Ut-100). I only need some data to show up on the screen, is there a simple way to simple return an array of bytes and handle it by myself? Thanks for any help</p>