我偶尔会看到提到 android.hardware.usb.action.USB_STATE
广播,据说其中包含一些 USB 状态信息。
它似乎不是官方 Android API 的一部分。是否有任何相关文档,特别是支持的附加功能列表?
最佳答案
来自platform_frameworks_base/core/java/android/hardware/usb/UsbManager.java :
该常量标有@UnsupportedAppUsage
,表示它不应该暴露给应用程序/由应用程序使用。这可能意味着它不能保证跨版本稳定。
此外, Intent 似乎是指示到主机的 USB 链路状态,而不是 USB OTG 状态。
UsbManager
的 javadoc 说:
This class allows you to access the state of USB and communicate with USB devices. Currently only host mode is supported in the public API.
对于ACTION_USB_STATE
:
Broadcast Action: A sticky broadcast for USB state change events when in device mode.
This is a sticky broadcast for clients that includes USB connected/disconnected state,
"connected"
boolean indicating whether USB is connected or disconnected."host_connected"
boolean indicating whether USB is connected or disconnected as host."configured"
boolean indicating whether USB is configured. currently zero if not configured, one for configured."adb"
boolean extra indicating whether the adb function is enabled"rndis"
boolean extra indicating whether the RNDIS ethernet function is enabled"mtp"
boolean extra indicating whether the MTP function is enabledUSB_FUNCTION_PTP
boolean extra indicating whether the PTP function is enabled"ptp"
boolean extra indicating whether the accessory function is enabled"audio_source"
boolean extra indicating whether the audio source function is enabled"midi"
boolean extra indicating whether the MIDI function is enabledIf the sticky intent has not been found, that indicates USB is disconnected, USB is not configued, MTP function is enabled, and all the other functions are disabled.
关于android - USB_STATE 广播的附加功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55013424/