UsbHid
Another custom USB HID host library for Android
Install / Use
/learn @siqneibi/UsbHidREADME
UsbHid
Another custom USB HID host library for Android. Inspired by:
https://android.serverbox.ch/?p=549
https://github.com/benlypan/UsbHid
https://github.com/yutils/yutils/blob/master/utils/src/main/java/com/yujing/utils/YUsb.kt
Benefits
- Register device vid:pid and the library will notify you, i.e. via events, if device is not found, connected, or disconnected.
- The library will request permission to use device (if needed)
- You can extend the UsbHidDevice class and include all your device related commands in the new class (see example app)
Usage
You need to setup repositories to use github packages (see example app):
repositories {
google()
mavenCentral()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/siqneibi/UsbHid")
credentials {
/**Create github.properties in root project folder file with gpr.usr=GITHUB_USER_ID & gpr.key=PERSONAL_ACCESS_TOKEN**/
username = githubProperties['gpr.usr']
password = githubProperties['gpr.key']
}
}
}
And add following line to dependencies section:
implementation 'co.sedco:usbhid:0.3.0'
QuickStart
Create a connection handler in your activity
private val mConnectionHandler: IUsbConnectionHandler = object :
IUsbConnectionHandler {
override fun onDeviceConnected() {
Log.d(TAG,"onDeviceConnected")
}
override fun onDeviceDisconnected() {
Log.d(TAG,"onDeviceDisconnected")
}
override fun onDeviceNotFound() {
Log.d(TAG,"onDeviceNotFound")
}
override fun onDevicePermissionDenied() {
Log.d(TAG,"onDevicePermissionDenied")
}
}
Extend the the UsbHidDevice class with your own custom behavior
class CustomHidDevice(appContext: Context, connectionHandler: IUsbConnectionHandler): UsbHidDevice(appContext, connectionHandler, MyVendorId, MyProductId) {
And finally instantiate the CustomHidDevice class in your activity and communicate with your HID device
hidDevice = CustomHidDevice(application.applicationContext, mConnectionHandler)
hidDevice.setDevice(DEVICE_LED1, DEVICE_BLINK)
val (result, value) = hidDevice.getDevice(DEVICE_SENSOR1)
For details, please see example application.
License
MIT
Related Skills
node-connect
350.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
