Android 휴대 전화에 연결하려는 복합 USB 가젯이 있습니다. 그것은 다음, 시리얼 MTP 및 대용량 저장 장치 인터페이스를 포함Android MTP 클라이언트가 단일 인터페이스가 아닌 전체 장치를 엽니 다.
interface :: id : 0, name : CDC Abstract Control Model (ACM), alt 0 [0002h:0002h:0001h] CDC Control
interface :: id : 1, name : CDC ACM Data, alt 0 [000ah:0000h:0000h] CDC Data
interface :: id : 2, name : MTP, alt 0 [00ffh:00ffh:0000h] Vendor Specific
interface :: id : 3, name : Mass Storage, alt 0 [0008h:0006h:0050h] Mass Storage
내 문제는 직렬 및 MTP 인터페이스 모두를 열려고 시도입니다. 여기 내 코드입니다 :
private class SetupInterfacesRunnable implements Runnable
{
@Override
public void run()
{
synchronized(MyService.this)
{
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
usbConnection = usbManager.openDevice(usbDevice);
/*
interface :: id : 0, name : CDC Abstract Control Model (ACM), alt 0 [0002h:0002h:0001h] CDC Control
interface :: id : 1, name : CDC ACM Data, alt 0 [000ah:0000h:0000h] CDC Data
interface :: id : 2, name : MTP, alt 0 [00ffh:00ffh:0000h] Vendor Specific
interface :: id : 3, name : Mass Storage, alt 0 [0008h:0006h:0050h] Mass Storage
*/
// Interface 1 on the composite usb device is cdc acm data.
serialPort = UsbSerialDevice.createUsbSerialDevice(usbDevice, usbConnection, 1);
if(serialPort != null)
{
if(serialPort.open())
{
serialPort.setBaudRate(115200);
serialPort.setDataBits(UsbSerialInterface.DATA_BITS_8);
serialPort.setParity(UsbSerialInterface.PARITY_NONE);
serialPort.setStopBits(UsbSerialInterface.STOP_BITS_1);
serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
mUIHandler.post(notifyRadgetConnected);
// set the callback to catch serial data
serialPort.read(mCallback);
mUIHandler.post(handshake);
}else
{
// Serial port could not be opened, maybe an I/O error or it CDC driver was chosen it does not really fit
LoggerV2.e("Failed to open device serial port");
}
}else
{
// No driver for given device, even generic CDC driver could not be loaded
LoggerV2.e("Failed to find driver for the serial device");
}
// Interface 2 on the composite usb device is MTP.
MtpDevice mtpDevice = new MtpDevice(usbDevice);
if (!mtpDevice.open(usbConnection)) {
LoggerV2.e("Failed to obtain device mtp storage");
}
}
}
}
내가 사용하고 일련의 구현 (felHR85/UsbSerial), 단일 인터페이스를 열 수 있지만, 나는이 방식으로 MTPDevice를 구현하는 쉬운 방법을 볼 수 없습니다 수 있습니다.
Android MTP API는 open 함수가 호출 될 때 전체 장치/연결이 열리길 원합니다.
native_open(mDevice.getDeviceName(), connection.getFileDescriptor());
API 문서 :https://developer.android.com/reference/android/mtp/MtpDevice.html
내가 볼 수없는 단 하나의 인터페이스를 열 수있는 방법. 연결을 사용하여 동일한 장치에 여러 인터페이스를 여는 간단한 방법이 누락 되었습니까?