【问题标题】:Does Accessory Mode require the device to be in MTP mode?附件模式是否要求设备处于 MTP 模式?
【发布时间】:2017-11-08 14:44:22
【问题描述】:

我正在尝试编写一个 Windows 应用程序来充当使用 libusb 和 Android Open Accessory 协议的 Android 设备的主机。

但是,我发现我什至无法与手机握手,除非它已经处于 MTP 模式(我正在针对 Pixel XL 进行测试,每次你都会恢复到“充电模式”拔掉它)。

我在网上找不到任何答案,所以我想我会在这里问。怎样才能连接到手机,而不必每次都手动将其置于 MTP 模式?

Windows libusb 代码如下:

std::vector<AndroidDevice> devices;

libusb_device *** listptr = new libusb_device **;

libusb_device ** list;

libusb_init(NULL);

int deviceCount = libusb_get_device_list(NULL, listptr);

list = *listptr;

delete listptr;

for (int i = 0; i < deviceCount; i++) {
    libusb_device * device = list[i];

    libusb_device_descriptor desc;

    int result = libusb_get_device_descriptor(device, &desc);

    if (desc.idVendor == GOOGLE_VENDOR_ID) {
        libusb_device_handle ** handleptr = new libusb_device_handle *;

        result = libusb_open(device, handleptr); //Returns "not supported" error unless phone is in MTP

        libusb_device_handle * handle = *handleptr;

        delete handleptr;

        if (!result) {
            devices.emplace_back(device, handle);
        }
        else {
            printf("Error opening device: %s\n", errorDescription(result).c_str());
        }
    }

【问题讨论】:

    标签: android usb libusb android-open-accessory


    【解决方案1】:

    据我所知,这是 Android 的安全功能,因此设备在用户下令之前不会连接到主机。选择 Android 设备上的选项更改 USB 小工具驱动程序配置,允许连接。

    Android 开发者选项中有一个选项应该能够更改此行为,如 here 所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 1970-01-01
      • 2023-04-10
      • 2012-09-03
      相关资源
      最近更新 更多