在Android上通过USB主机模式访问相机存储

时间:2015-07-31 08:38:20

标签: android io usb usb-otg

我试图通过USB主机使用我的OTG线缆访问我的DSLR上的SD卡。我相信这是通过PTP。我已经看过几个可以执行此操作但没有root权限的应用程序,不仅可以访问它们,还可以控制快门速度和内容。但我只对访问DSLR上的SD卡感兴趣。连接USB设备后我卡住了。见附件代码

private void checkInfo() {
        manager = (UsbManager) getSystemService(Context.USB_SERVICE);
        /*
         * this block required if you need to communicate to USB devices it's
         * take permission to device
         * if you want than you can set this to which device you want to communicate
         */
        // ------------------------------------------------------------------
        mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(
                ACTION_USB_PERMISSION), 0);
        IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
        registerReceiver(mUsbReceiver, filter);
        // -------------------------------------------------------------------
        HashMap<String , UsbDevice> deviceList = manager.getDeviceList();
        Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
        String i = "";
        while (deviceIterator.hasNext()) {
            device = deviceIterator.next();
            manager.requestPermission(device, mPermissionIntent);
            i += "\n" + "DeviceID: " + device.getDeviceId() + "\n"
                    + "DeviceName: " + device.getDeviceName() + "\n"
                    + "DeviceClass: " + device.getDeviceClass() + " - "
                    + "DeviceSubClass: " + device.getDeviceSubclass() + "\n"
                    + "VendorID: " + device.getVendorId() + "\n"
                    + "ProductID: " + device.getProductId() + "\n";
        }

        textInfo.setText(i);
    }

有人可以告诉我如何阅读,然后最终将照片从DSLR的SD卡下载到我的Android应用程序。

更新

所以我尝试了这个库https://github.com/mjdev/libaums

它很棒,但它只支持USB大容量存储。它不会识别我的相机存储。

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

Android的文档使用一般的MTP术语,但它实际上只支持PTP子集,这很好,因为这是你要问的协议。