android - USB_STATE 广播的附加功能

标签 android usb

我偶尔会看到提到 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 enabled
  • USB_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 enabled

If 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/

相关文章:

delphi - 如何以编程方式连接和重新连接 USB 设备

visual-c++ - 如何唯一识别USB设备?

format - Google Play的FT311D配件启动应用程序

java - 什么是 'savedInstanceState' ?

java - onActivityResult 未从修复的警报对话框中触发

android - 在带有选项卡的 SherlockFragmentActivity 中使用 PreferenceFragment

android - 在 Visual Studio 2022 的 Xamarin 上,我不断收到 "There were deployment errors continue?"我在 Windows 11 上,我正在使用 Android 模拟器

从 linux 主机控制 Jabra 710 USB 扬声器音量

macos - 如何使用 Cocoa 或其他任何工具在 Mac OS X 10.6 上同时使用 USB 扬声器和内置音频扬声器?

java - float 比较不匹配