【问题标题】:How to detect whether my android device supports otg cable in android如何检测我的android设备是否支持android中的otg电缆
【发布时间】:2015-02-07 11:14:48
【问题描述】:

我想检测我的安卓智能手机是否支持 USB On-The-Go 。我在互联网上搜索了很多,但找不到任何方法!

我发现有一个应用程序“USB OTG Checker”。这是该应用程序的一些屏幕截图。

如何检查智能手机是否插入了 USB?

【问题讨论】:

  • 这和编程有什么关系?

标签: android usb-drive usb-otg


【解决方案1】:

其实USB Host其实和OTG差不多,因为我们可以通过程序检查USB Host功能,这里是我的解决方案,希望对你有帮助。

    /**
 * Check the device whether has USB-HOST feature.
 */
public static boolean hasUsbHostFeature(Context context) {
    return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST);
}

【讨论】:

    【解决方案2】:

    您的答案在这里:https://stackoverflow.com/a/34691806/3818437

    在您的manifest 中添加<uses-feature> 元素,表示您对android.hardware.usb.host 功能感兴趣。

    使用PackageManager, hasSystemFeature(), and FEATURE_USB_HOSTFEATURE_USB_HOST 定义为与您将在 <uses-feature>(android.hardware.usb.host) 中使用的字符串相同的字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-07
      • 2011-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多