Added in API level 12

UsbDevice


open class UsbDevice : Parcelable
kotlin.Any
   ↳ android.hardware.usb.UsbDevice

This class represents a USB device attached to the android device with the android device acting as the USB host. Each device contains one or more UsbInterfaces, each of which contains a number of UsbEndpoints (the channels via which data is transmitted over USB).

This class contains information (along with UsbInterface and UsbEndpoint) that describes the capabilities of the USB device. To communicate with the device, you open a UsbDeviceConnection for the device and use UsbRequest to send and receive data on an endpoint. android.hardware.usb.UsbDeviceConnection#controlTransfer is used for control requests on endpoint zero.

Summary

Inherited constants
Public methods
open Int

open Boolean
equals(other: Any?)

Indicates whether some other object is "equal to" this one.

open UsbConfiguration

Returns the UsbConfiguration at the given index.

open Int

Returns the number of UsbConfigurations this device contains.

open Int

Returns the devices's class field.

open Int

Returns a unique integer ID for the device.

open static Int

open String

Returns the name of the device.

open static String!

open Int

Returns the device's protocol field.

open Int

Returns the device's subclass field.

open UsbInterface
getInterface(index: Int)

Returns the UsbInterface at the given index.

open Int

Returns the number of UsbInterfaces this device contains.

open String?

Returns the manufacturer name of the device.

open Int

Returns a product ID for the device.

open String?

Returns the product name of the device.

open String?

Returns the serial number of the device.

open Int

Returns a vendor ID for the device.

open String

Returns the version number of the device.

open Int

open String

open Unit
writeToParcel(parcel: Parcel, flags: Int)

Properties
static Parcelable.Creator<UsbDevice!>

Public methods

describeContents

Added in API level 12
open fun describeContents(): Int
Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

equals

Added in API level 12
open fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj the reference object with which to compare.
o This value may be null.
Return
Boolean true if this object is the same as the obj argument; false otherwise.

getConfiguration

Added in API level 21
open fun getConfiguration(index: Int): UsbConfiguration

Returns the UsbConfiguration at the given index.

Return
UsbConfiguration the configuration This value cannot be null.

getConfigurationCount

Added in API level 21
open fun getConfigurationCount(): Int

Returns the number of UsbConfigurations this device contains.

Return
Int the number of configurations

getDeviceClass

Added in API level 12
open fun getDeviceClass(): Int

Returns the devices's class field. Some useful constants for USB device classes can be found in UsbConstants.

Return
Int the devices's class

getDeviceId

Added in API level 12
open fun getDeviceId(): Int

Returns a unique integer ID for the device. This is a convenience for clients that want to use an integer to represent the device, rather than the device name. IDs are not persistent across USB disconnects.

Return
Int the device ID

getDeviceId

Added in API level 12
open static fun getDeviceId(name: String!): Int

getDeviceName

Added in API level 12
open fun getDeviceName(): String

Returns the name of the device. In the standard implementation, this is the path of the device file for the device in the usbfs file system.

Return
String the device name This value cannot be null.

getDeviceName

Added in API level 12
open static fun getDeviceName(id: Int): String!

getDeviceProtocol

Added in API level 12
open fun getDeviceProtocol(): Int

Returns the device's protocol field.

Return
Int the device's protocol

getDeviceSubclass

Added in API level 12
open fun getDeviceSubclass(): Int

Returns the device's subclass field.

Return
Int the device's subclass

getInterface

Added in API level 12
open fun getInterface(index: Int): UsbInterface

Returns the UsbInterface at the given index. For devices with multiple configurations, you will probably want to use UsbConfiguration.getInterface instead.

Return
UsbInterface the interface This value cannot be null.

getInterfaceCount

Added in API level 12
open fun getInterfaceCount(): Int

Returns the number of UsbInterfaces this device contains. For devices with multiple configurations, you will probably want to use UsbConfiguration.getInterfaceCount instead.

Return
Int the number of interfaces

getManufacturerName

Added in API level 21
open fun getManufacturerName(): String?

Returns the manufacturer name of the device.

Return
String? the manufacturer name, or null if the property could not be read

getProductId

Added in API level 12
open fun getProductId(): Int

Returns a product ID for the device.

Return
Int the device product ID

getProductName

Added in API level 21
open fun getProductName(): String?

Returns the product name of the device.

Return
String? the product name, or null if the property could not be read

getSerialNumber

Added in API level 21
open fun getSerialNumber(): String?

Returns the serial number of the device.

Return
String? the serial number name, or null if the property could not be read
Exceptions
java.lang.SecurityException if the app targets SDK >= {@value android.os.Build.VERSION_CODES#Q} and the app does not have permission to read from the device.

getVendorId

Added in API level 12
open fun getVendorId(): Int

Returns a vendor ID for the device.

Return
Int the device vendor ID

getVersion

Added in API level 23
open fun getVersion(): String

Returns the version number of the device.

Return
String the device version This value cannot be null.

hashCode

Added in API level 12
open fun hashCode(): Int
Return
Int a hash code value for this object.

toString

Added in API level 12
open fun toString(): String
Return
String a string representation of the object.

writeToParcel

Added in API level 12
open fun writeToParcel(
    parcel: Parcel,
    flags: Int
): Unit
Parameters
dest The Parcel in which the object should be written. This value cannot be null.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Properties

CREATOR

Added in API level 12
static val CREATOR: Parcelable.Creator<UsbDevice!>