/UsbListener

Android library for listening USB device attached and detached event when in host mode.

Primary LanguageKotlin

Release

MinSDK TargetSDK

Kotlin

UsbListener

Android library for listening USB device attached and detached event when in host mode.

Setup

  1. In root build.gradle:
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
  1. In target module build.gradle
dependencies {
    compile 'com.github.xpathexception:UsbListener:1.0.0'
}

Usage

Following sample code shows how to initialize listener with permission request:

val usbListener = UsbListener(this, true, object : UsbListener.UsbDeviceListener {
    override fun onAttached(device: UsbDevice) {
        //to do
    }

    override fun onDetached(device: UsbDevice) {
        //to do
    }
})

Don't forget to dispose it when no longer need:

usbListener.dispose()

Reworked from https://github.com/potterhsu/UsbListener