USBMonitor

class USBMonitor

Constructors

USBMonitor
Link copied to clipboard
open fun USBMonitor(context: Context, listener: USBMonitor.OnDeviceConnectListener)

Types

OnDeviceConnectListener
Link copied to clipboard
interface OnDeviceConnectListener
USB機器の状態変更時のコールバックリスナー
UsbControlBlock
Link copied to clipboard
class UsbControlBlock : Cloneable
control classnever reuse the instance when it closed
UsbDeviceInfo
Link copied to clipboard
open class UsbDeviceInfo

Functions

addDeviceFilter
Link copied to clipboard
open fun addDeviceFilter(filter: DeviceFilter)
デバイスフィルターを追加
open fun addDeviceFilter(filters: List<DeviceFilter>)
add device filters
destroy
Link copied to clipboard
open fun destroy()
Release all related resources,never reuse again
dumpDevices
Link copied to clipboard
fun dumpDevices()
output device list to LogCat
getDeviceCount
Link copied to clipboard
open fun getDeviceCount(): Int
return the number of connected USB devices that matched device filter
getDeviceInfo
Link copied to clipboard
open fun getDeviceInfo(device: UsbDevice): USBMonitor.UsbDeviceInfo
ベンダー名・製品名・バージョン・シリアルを取得する
open fun getDeviceInfo(context: Context, device: UsbDevice): USBMonitor.UsbDeviceInfo
ベンダー名・製品名・バージョン・シリアルを取得する#updateDeviceInfo(final UsbManager, final UsbDevice, final UsbDeviceInfo)のヘルパーメソッド
getDeviceKey
Link copied to clipboard
fun getDeviceKey(device: UsbDevice): Int
デバイスキーを整数として取得getDeviceKeyNameで得られる文字列のhasCodeを取得ベンダーID, プロダクトID, デバイスクラス, デバイスサブクラス, デバイスプロトコルから生成同種の製品だと同じデバイスキーになるので注意
fun getDeviceKey(device: UsbDevice, useNewAPI: Boolean): Int
デバイスキーを整数として取得getDeviceKeyNameで得られる文字列のhasCodeを取得useNewAPI=falseで同種の製品だと同じデバイスキーになるので注意
fun getDeviceKey(device: UsbDevice, serial: String, useNewAPI: Boolean): Int
デバイスキーを整数として取得getDeviceKeyNameで得られる文字列のhasCodeを取得serialがnullでuseNewAPI=falseで同種の製品だと同じデバイスキーになるので注意
getDeviceKeyName
Link copied to clipboard
fun getDeviceKeyName(device: UsbDevice): String
USB機器毎の設定保存用にデバイスキー名を生成する。ベンダーID, プロダクトID, デバイスクラス, デバイスサブクラス, デバイスプロトコルから生成同種の製品だと同じキー名になるので注意
fun getDeviceKeyName(device: UsbDevice, useNewAPI: Boolean): String
USB機器毎の設定保存用にデバイスキー名を生成する。useNewAPI=falseで同種の製品だと同じデバイスキーになるので注意
fun getDeviceKeyName(device: UsbDevice, serial: String, useNewAPI: Boolean): String
USB機器毎の設定保存用にデバイスキー名を生成する。この機器名をHashMapのキーにするUsbDeviceがopenしている時のみ有効ベンダーID, プロダクトID, デバイスクラス, デバイスサブクラス, デバイスプロトコルから生成serialがnullや空文字でなければserialを含めたデバイスキー名を生成するuseNewAPI=trueでAPIレベルを満たしていればマニュファクチャ名, バージョン, コンフィギュレーションカウントも使う
getDeviceList
Link copied to clipboard
open fun getDeviceList(): List<UsbDevice>
return device list, return empty list if no device matched
open fun getDeviceList(filter: DeviceFilter): List<UsbDevice>
return device list, return empty list if no device matched
open fun getDeviceList(filters: List<DeviceFilter>): List<UsbDevice>
return device list, return empty list if no device matched
getDevices
Link copied to clipboard
open fun getDevices(): Iterator<UsbDevice>
get USB device list, without filter
hasPermission
Link copied to clipboard
fun hasPermission(device: UsbDevice): Boolean
return whether the specific Usb device has permission
isRegistered
Link copied to clipboard
open fun isRegistered(): Boolean
openDevice
Link copied to clipboard
open fun openDevice(device: UsbDevice): USBMonitor.UsbControlBlock
指定したUsbDeviceをopenする
register
Link copied to clipboard
open fun register()
register BroadcastReceiver to monitor USB events
removeDeviceFilter
Link copied to clipboard
open fun removeDeviceFilter(filter: DeviceFilter)
デバイスフィルターを削除
open fun removeDeviceFilter(filters: List<DeviceFilter>)
remove device filters
requestPermission
Link copied to clipboard
open fun requestPermission(device: UsbDevice): Boolean
request permission to access to USB device
setDeviceFilter
Link copied to clipboard
open fun setDeviceFilter(filter: DeviceFilter)
set device filter
open fun setDeviceFilter(filters: List<DeviceFilter>)
set device filters
unregister
Link copied to clipboard
open fun unregister()
unregister BroadcastReceiver
updateDeviceInfo
Link copied to clipboard
open fun updateDeviceInfo(manager: UsbManager, device: UsbDevice, _info: USBMonitor.UsbDeviceInfo): USBMonitor.UsbDeviceInfo
ベンダー名・製品名・バージョン・シリアルを取得する

Properties

ACTION_USB_DEVICE_ATTACHED
Link copied to clipboard
val ACTION_USB_DEVICE_ATTACHED: String