當前位置: 首頁>>代碼示例>>Java>>正文


Java UsbDeviceConnection.claimInterface方法代碼示例

本文整理匯總了Java中android.hardware.usb.UsbDeviceConnection.claimInterface方法的典型用法代碼示例。如果您正苦於以下問題:Java UsbDeviceConnection.claimInterface方法的具體用法?Java UsbDeviceConnection.claimInterface怎麽用?Java UsbDeviceConnection.claimInterface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.hardware.usb.UsbDeviceConnection的用法示例。


在下文中一共展示了UsbDeviceConnection.claimInterface方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setAdbInterface

import android.hardware.usb.UsbDeviceConnection; //導入方法依賴的package包/類
private boolean setAdbInterface(UsbDevice device, UsbInterface intf) {
    if (mDeviceConnection != null) {
        if (mInterface != null) {
            mDeviceConnection.releaseInterface(mInterface);
            mInterface = null;
        }
        mDeviceConnection.close();
        mDevice = null;
        mDeviceConnection = null;
    }

    if (device != null && intf != null) {
        UsbDeviceConnection connection = mManager.openDevice(device);
        if (connection != null) {
            log("open succeeded");
            if (connection.claimInterface(intf, false)) {
                log("claim interface succeeded");
                mDevice = device;
                mDeviceConnection = connection;
                mInterface = intf;
                mAdbDevice = new AdbDevice(this, mDeviceConnection, intf);
                log("call start");
                mAdbDevice.start();
                return true;
            } else {
                log("claim interface failed");
                connection.close();
            }
        } else {
            log("open failed");
        }
    }

    if (mDeviceConnection == null && mAdbDevice != null) {
        mAdbDevice.stop();
        mAdbDevice = null;
    }
    return false;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:40,代碼來源:AdbTestActivity.java

示例2: open

import android.hardware.usb.UsbDeviceConnection; //導入方法依賴的package包/類
@Override
public void open(UsbDeviceConnection connection) throws IOException {
    if (mConnection != null) {
        throw new IOException("Already open");
    }
    mConnection = connection;

    boolean opened = false;
    try {
        for (int i = 0; i < mDevice.getInterfaceCount(); i++) {
            if (connection.claimInterface(mDevice.getInterface(i), true)) {
                Log.d(TAG, "claimInterface " + i + " SUCCESS");
            } else {
                throw new IOException("Error claiming interface " + i);
            }
        }
        reset();
        opened = true;
    } finally {
        if (!opened) {
            close();
            mConnection = null;
        }
    }
}
 
開發者ID:msillano,項目名稱:USBphpTunnel,代碼行數:26,代碼來源:FtdiSerialDriver.java

示例3: setupUsb

import android.hardware.usb.UsbDeviceConnection; //導入方法依賴的package包/類
protected void setupUsb(UsbDevice device) {
    UsbInterface inf = device.getInterface(0);
    UsbDeviceConnection conn = mUsbManager.openDevice(device);
    if (conn == null) {
        Log.wtf("MainActivity", "unable to open device?");
        return;
    }

    if (!conn.claimInterface(inf, true)) {
        conn.close();
        Log.wtf("MainActivity", "unable to claim interface!");
        return;
    }

    mBlinkDevice = device;
    mBlinkConn = conn;
}
 
開發者ID:nasa,項目名稱:astrobee_android,代碼行數:18,代碼來源:MainActivity.java

示例4: setDevice

import android.hardware.usb.UsbDeviceConnection; //導入方法依賴的package包/類
private boolean setDevice(UsbDevice device) {
    Logger.d("setDevice " + device);
    clearDevice();
    if (null == device) {
        return false;
    }
    if (device.getVendorId() != mVendorId) {
        printDevice(device);
        Logger.i("Not a target vendor: expecting %d", mVendorId);
        return false;
    }
    if (device.getProductId() != mProductId) {
        printDevice(device);
        Logger.i("Not a target product: expecting %d", mProductId);
        return false;
    }
    if (!mUsbManager.hasPermission(device)) {
        Logger.d("request permission");
        mUsbManager.requestPermission(device, mPermissionIntent);
        return false;
    }
    printDevice(device);
    try {
        UsbInterface usbinterface = device.getInterface(0);
        UsbDeviceConnection connection = mUsbManager.openDevice(device);
        if (!connection.claimInterface(usbinterface, true)) {
            return false;
        }
        mDevice = device;
        mConnection = connection;
        Logger.d("open SUCCESS");
        if (null != mOnDeviceListener) {
            mOnDeviceListener.onAttached();
        }
        return true;
    } catch (Exception e) {
        Logger.e(e, e.getLocalizedMessage());
    }
    return false;
}
 
開發者ID:dena-csr,項目名稱:bootloadHID-android,代碼行數:41,代碼來源:UsbWriter.java

示例5: setUsbInterface

import android.hardware.usb.UsbDeviceConnection; //導入方法依賴的package包/類
private boolean setUsbInterface(android.hardware.usb.UsbDevice device, UsbInterface intf) {
    if (mDeviceConnection != null) {
        if (mInterface != null) {
            mDeviceConnection.releaseInterface(mInterface);
            mInterface = null;
        }
        mDeviceConnection.close();
        mDevice = null;
        mDeviceConnection = null;
    }

    if (device != null && intf != null) {
        UsbDeviceConnection connection = mUsbManager.openDevice(device);
        if (connection != null) {
            if (connection.claimInterface(intf, true)) {
                mDevice = device;
                mDeviceConnection = connection;
                mInterface = intf;
                mFcDevice = new FcUsbDevice(this, mDeviceConnection, intf,
                        mXmlObjects);
                mFcDevice.getObjectTree().setXmlObjects(mXmlObjects);

                mFcDevice.start();
                return true;
            } else {
                connection.close();
            }
        }
    }

    if (mDeviceConnection == null && mFcDevice != null) {
        mFcDevice.stop();
        mFcDevice = null;
    }
    return false;
}
 
開發者ID:MarcProe,項目名稱:lp2go,代碼行數:37,代碼來源:MainActivity.java

示例6: open

import android.hardware.usb.UsbDeviceConnection; //導入方法依賴的package包/類
@Override
public void open(UsbDeviceConnection connection) throws IOException {
    if (mConnection != null) {
        throw new IOException("Already open");
    }
    mConnection = connection;

    boolean opened = false;
    try {
        for (int i = 0; i < mDevice.getInterfaceCount(); i++) {
            if (connection.claimInterface(mDevice.getInterface(i), true)) {
                L.INSTANCE.d("claimInterface " + i + " SUCCESS");
            } else {
                throw new IOException("Error claiming interface " + i);
            }
        }
        reset();
        opened = true;
    } finally {
        if (!opened) {
            close();
            mConnection = null;
        }
    }
}
 
開發者ID:HelloHuDi,項目名稱:usb-with-serial-port,代碼行數:26,代碼來源:FtdiSerialDriver.java


注:本文中的android.hardware.usb.UsbDeviceConnection.claimInterface方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。