Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么打开设备后UsbDeviceConnection claimInterface失败_Android - Fatal编程技术网

Android 为什么打开设备后UsbDeviceConnection claimInterface失败

Android 为什么打开设备后UsbDeviceConnection claimInterface失败,android,Android,我编写了一个应用程序,通过USB主机与自己的设备通信。像这样的代码块 UsbDeviceConnection connection = mUsbManager.openDevice(mDevice); if (connection == null) { Log.d(TAG, "open device failed"); break; } Log.d(TAG, "Opening the usb device success"); if (!connection.claimInter

我编写了一个应用程序,通过USB主机与自己的设备通信。像这样的代码块

UsbDeviceConnection connection = mUsbManager.openDevice(mDevice);
if (connection == null) {
    Log.d(TAG, "open device failed");
    break;
}
Log.d(TAG, "Opening the usb device success");
if (!connection.claimInterface(ui, true)) {
    connection.close();
    Log.d(TAG, "Usb claim interface failed");
    break;
}
日志显示

D/UsbhostModbusAdapter: Opening the usb device success
D/UsbDeviceConnectionJNI: close 
D/UsbhostModbusAdapter: Usb claim interface failed
我注意到在调用openDevice后,JNI关闭了该设备。那么openDevice和claimInterface之间发生了什么?这是硬件问题吗


PS:有时同一设备可以声称成功并发送/接收数据正常。这取决于插入手机时的打开操作。当第一次打开正常时,关闭并重新打开始终正常。但是如果第一次打开时不正常,那么它将永远不会正常打开。

您没有解释调用此代码的事件。
如果
1.您的部分代码将被背靠背调用两次,而不关闭以前的连接。
2.当您的活动被销毁时,您将丢失对connection.close()的调用,因为以前的连接会占用设备