3

using web serial API in windows, mac os, and Linux chrome browser I can receive and send data. but in the android chrome browser, I am not able to send or receive data from a serial device.

so which API is used to read and write data to serial devices in the android chrome browser.

also, there is a polyfill serial API for android chrome but is showing an error shown in the image.enter image description here

Tejas Chauhan
  • 69
  • 3
  • 9
  • Are you aware of: https://caniuse.com/?search=serial – Morrison Chang May 12 '22 at 05:50
  • yes. I have read, that web serial API is not supported in android chrome. but is there another way to communicate with a serial(USB-based) device from android chrome? because my PWA project requires access on both desktop and mobile. – Tejas Chauhan May 12 '22 at 06:18
  • Given that Android apps written in Java/Kotlin need/use a third-party library to support USB Serial: https://github.com/mik3y/usb-serial-for-android it is unlikely unless the browser has similar code. – Morrison Chang May 12 '22 at 06:34
  • okay!! thanks for answering! using this I have to build. APK file. using this I can communicate to the serial device. – Tejas Chauhan May 12 '22 at 06:58

1 Answers1

2

The team that built the implementation of the Web Serial API in Chromium also wrote a polyfill library which uses WebUSB to support platforms which don't provide built-in serial drivers: https://github.com/google/web-serial-polyfill

It looks like you are already trying to use this library. Can you file an issue on the library's GitHub project so the team can look at the error you're seeing?

Note, it seems like there are some Android devices which have USB serial drivers that end up blocking WebUSB from claiming interfaces even though the platform doesn't let apps actually use them. https://crbug.com/1099521 is tracking a workaround for that.

Reilly Grant
  • 5,590
  • 1
  • 13
  • 23
  • yes of course! I will file the issue on the GitHub project. – Tejas Chauhan May 13 '22 at 05:34
  • can you tell me? how much time does the serial polyfill API take to launch, so that use this API on the android chrome browser to communicate with serial devices without any error. – Tejas Chauhan May 17 '22 at 05:24
  • The workaround link is a little confusing to follow. In its current 2022 state, does WebUSB on Android call the linked JNI Android code? I don't think it does because it is as if the kernel module is never detached when trying to talk to a USB-CDC class device on Android from what I can tell. – Brandon Ros Nov 30 '22 at 14:57