AndroidSerialPorts

Android-side USB serial discovery and transport construction.

jSerialComm 2.11.x on Android relies on JSerialPort.setAndroidContext being called once with an Application (or other long-lived) Context so the library can resolve the system UsbManager and request opens against permissioned UsbDevices. The caller is responsible for the standard UsbManager.requestPermission(device, pendingIntent) flow before the device shows up in list and can be opened.

Required AndroidManifest.xml entries for the host app:

<uses-feature android:name="android.hardware.usb.host" />
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>

Properties

Link copied to clipboard
const val DEFAULT_BAUD: Int

Functions

Link copied to clipboard
fun init(context: Context)

Bind jSerialComm to the supplied Android Context. Safe to call more than once; only the most recent context is retained. Should typically be passed an Application context.

Link copied to clipboard

Enumerate USB serial ports the host app currently has permission for.

Link copied to clipboard
fun open(portName: String, baudRate: Int = DEFAULT_BAUD): RadioTransport

Open the named serial port. The port name is the SerialPortInfo.name value returned by list; under the hood jSerialComm derives this from the underlying USB device.

Link copied to clipboard

Convenience pass-through for enumerating raw UsbDevices the system exposes (regardless of permission state). Useful for building a permission-prompt picker UI.