1

Basically I have a React Native application which has one of the screens, where I have to listen to the external Bluetooth QR codes scanner which works as a HID device (!) which is already connected to the mobile device, not to the application itself.

Am I right that:

  1. I even shouldn't establish the bluetooth usage permissions in the app
  2. Since the QR code scanner works as HID device, I simply have to listen to the external data input once I entered this screen, and stop listening when I leave this screen?

If yes - then how? Thank you in advance

123dumoh
  • 11
  • 2
  • What platform is this running on? On Android, you'll likely need to interact with BluetoothHidDevice. On macOS, you'll likely go through IOKit. On iOS, there is no direct access to HID devices. This isn't a question of React Native. You'll need to either write something native, or find a RN framework that wraps the native calls. (Framework recommendations are generally off-topic for SO; but I would recommend searching at GitHub.) – Rob Napier Jun 30 '23 at 14:47
  • I would expect the device to have documentation about how to communicate with it. What does it say you should do (unrelated to React Native)? – Rob Napier Jun 30 '23 at 14:53
  • I will need to adapt it for both platforms, and honestly I do not expect to write something native for this integration. I'm sure tons of RN apps work with external scanners but I'm trying to figure our the way they listen to its data input. Thanks for the IOKit recommendation - I didn't think to take a look there, but will do in a moment. – 123dumoh Jun 30 '23 at 17:02
  • If by "both platforms" you're including iOS, this is generally not possible on iOS (at least via directly interacting with HID). As noted, IOKit is for macOS. See Risto's answer for how you may be able to read this, if it comes in as a keyboard or similar device, but unless this product exposes something that iOS apps can read, it may be impossible. I would start with the vendor's documentation. – Rob Napier Jun 30 '23 at 17:28

1 Answers1

1

HID devices, like cable-bound devices, are already processed by the OS kernel and the corresponding messages are not even passed through to the application.

However, your application can access the resulting events (key, mouse or similar) and use them to design its function.

Broken down to an application example with a text field and a QR code that is to be read into this text field via the HID QR code scanner, this would mean:

  • Call up the corresponding dialogue in your application
  • Set the input focus on the corresponding input field
  • Read the QR code via scanner
Risto
  • 983
  • 7
  • 14