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


Java UsbDevice.getInterface方法代碼示例

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


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

示例1: enumerate

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public static UsbHidDevice[] enumerate(Context context, int vid, int pid) throws Exception {
    UsbManager usbManager = (UsbManager) context.getApplicationContext().getSystemService(Context.USB_SERVICE);
    if (usbManager == null) {
        throw new Exception("no usb service");
    }

    Map<String, UsbDevice> devices = usbManager.getDeviceList();
    List<UsbHidDevice> usbHidDevices = new ArrayList<>();
    for (UsbDevice device : devices.values()) {
        if ((vid == 0 || device.getVendorId() == vid) && (pid == 0 || device.getProductId() == pid)) {
            for (int i = 0; i < device.getInterfaceCount(); i++) {
                UsbInterface usbInterface = device.getInterface(i);
                if (usbInterface.getInterfaceClass() == INTERFACE_CLASS_HID) {
                    UsbHidDevice hidDevice = new UsbHidDevice(device, usbInterface, usbManager);
                    usbHidDevices.add(hidDevice);
                }
            }
        }
    }
    return usbHidDevices.toArray(new UsbHidDevice[usbHidDevices.size()]);
}
 
開發者ID:benlypan,項目名稱:UsbHid,代碼行數:22,代碼來源:UsbHidDevice.java

示例2: open

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
/**
 * open specific interface
 * @param interfaceIndex
 * @return
 */
public synchronized UsbInterface open(final int interfaceIndex) {
	if (DEBUG) Log.i(TAG, "UsbControlBlock#open:" + interfaceIndex);
	final UsbDevice device = mWeakDevice.get();
	UsbInterface intf = null;
	intf = mInterfaces.get(interfaceIndex);
	if (intf == null) {
		intf = device.getInterface(interfaceIndex);
		if (intf != null) {
			synchronized (mInterfaces) {
				mInterfaces.append(interfaceIndex, intf);
			}
		}
	}
	return intf;
}
 
開發者ID:wjchen,項目名稱:AndroidUvcCameras,代碼行數:21,代碼來源:USBMonitor.java

示例3: Af9035DvbDevice

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
Af9035DvbDevice(UsbDevice usbDevice, Context context, DeviceFilter filter) throws DvbException {
    super(usbDevice, context, filter, DvbDemux.DvbDmxSwfilter());
    iface = usbDevice.getInterface(0);

    controlEndpointIn = iface.getEndpoint(0);
    controlEndpointOut = iface.getEndpoint(1);
    endpoint = iface.getEndpoint(2);
    // Endpoint 3 is a TS USB_DIR_IN endpoint with address 0x85
    // but I don't know what it is used for

    if (controlEndpointIn.getAddress() != 0x81 || controlEndpointIn.getDirection() != USB_DIR_IN)
        throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
    if (controlEndpointOut.getAddress() != 0x02 || controlEndpointOut.getDirection() != USB_DIR_OUT)
        throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
    if (endpoint.getAddress() != 0x84 || endpoint.getDirection() != USB_DIR_IN)
        throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
}
 
開發者ID:martinmarinov,項目名稱:AndroidDvbDriver,代碼行數:18,代碼來源:Af9035DvbDevice.java

示例4: readDevice

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
/**
 * Enumerate the endpoints and interfaces on the connected device.
 *
 * @param device Device to query.
 * @return String description of the device configuration.
 */
public static String readDevice(UsbDevice device) {
    StringBuilder sb = new StringBuilder();
    sb.append("Device Name: " + device.getDeviceName() + "\n");
    sb.append(String.format(
            "Device Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n",
            nameForClass(device.getDeviceClass()),
            device.getDeviceSubclass(), device.getDeviceProtocol()));

    for (int i = 0; i < device.getInterfaceCount(); i++) {
        UsbInterface intf = device.getInterface(i);
        sb.append(String.format(Locale.US,
                "-- Interface %d Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n",
                intf.getId(),
                nameForClass(intf.getInterfaceClass()),
                intf.getInterfaceSubclass(),
                intf.getInterfaceProtocol()));

        sb.append(String.format(Locale.US, "   -- Endpoint Count: %d\n",
                intf.getEndpointCount()));
    }

    return sb.toString();
}
 
開發者ID:androidthings,項目名稱:sample-usbenum,代碼行數:30,代碼來源:UsbHelper.java

示例5: isCdcDevice

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public static boolean isCdcDevice(UsbDevice device)
{
    int iIndex = device.getInterfaceCount();
    for(int i=0;i<=iIndex-1;i++)
    {
        UsbInterface iface = device.getInterface(i);
        if(iface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
            return true;
    }
    return false;
}
 
開發者ID:BITPlan,項目名稱:can4eve,代碼行數:12,代碼來源:UsbSerialDevice.java

示例6: setupUsb

import android.hardware.usb.UsbDevice; //導入方法依賴的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

示例7: Rtl28xxDvbDevice

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
Rtl28xxDvbDevice(UsbDevice usbDevice, Context context, DeviceFilter deviceFilter) throws DvbException {
    super(usbDevice, context, deviceFilter, DvbDemux.DvbDmxSwfilter());
    iface = usbDevice.getInterface(0);
    endpoint = iface.getEndpoint(0);

    if (endpoint.getAddress() != 0x81) throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
}
 
開發者ID:martinmarinov,項目名稱:AndroidDvbDriver,代碼行數:8,代碼來源:Rtl28xxDvbDevice.java

示例8: CxUsbDvbDevice

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
CxUsbDvbDevice(UsbDevice usbDevice, Context context, DeviceFilter filter) throws DvbException {
    super(usbDevice, context, filter, DvbDemux.DvbDmxSwfilter());

    iface = usbDevice.getInterface(0);

    controlEndpointIn = iface.getEndpoint(0);
    controlEndpointOut = iface.getEndpoint(1);
    endpoint = iface.getEndpoint(2);

    if (controlEndpointIn.getAddress() != 0x81 || controlEndpointIn.getDirection() != USB_DIR_IN) throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
    if (controlEndpointOut.getAddress() != 0x01 || controlEndpointOut.getDirection() != USB_DIR_OUT) throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
    if (endpoint.getAddress() != 0x82 || endpoint.getDirection() != USB_DIR_IN) throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
}
 
開發者ID:martinmarinov,項目名稱:AndroidDvbDriver,代碼行數:14,代碼來源:CxUsbDvbDevice.java

示例9: findUsbInterface

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
private UsbInterface findUsbInterface(UsbDevice device) {
    //Log.d (TAG, "findAdbInterface " + device.getDeviceName());
    int count = device.getInterfaceCount();
    for (int i = 0; i < count; i++) {
        UsbInterface intf = device.getInterface(i);
        Log.d (TAG, "Interface " +i + " Class " +intf.getInterfaceClass() +" Prot " +intf.getInterfaceProtocol());
        if (intf.getInterfaceClass() == 6
            //255 && intf.getInterfaceSubclass() == 66 && intf.getInterfaceProtocol() == 1
                ) {
            return intf;
        }
    }
    return null;
}
 
開發者ID:iyundong,項目名稱:InstantUpload,代碼行數:15,代碼來源:ControllerActivity.java

示例10: findUsbInterface

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
protected UsbInterface findUsbInterface(UsbDevice device) {
	//Log.d (TAG, "findAdbInterface " + device.getDeviceName());
	int count = device.getInterfaceCount();
	for (int i = 0; i < count; i++) {
		UsbInterface intf = device.getInterface(i);
		Log.d (TAG, "Interface " +i + " Class " +intf.getInterfaceClass() +" Prot " +intf.getInterfaceProtocol());
		if (intf.getInterfaceClass() == 6
				//255 && intf.getInterfaceSubclass() == 66 && intf.getInterfaceProtocol() == 1
				) {
			return intf;
		}
	}
	return null;
}
 
開發者ID:iyundong,項目名稱:InstantUpload,代碼行數:15,代碼來源:BaselineInitiator.java

示例11: findAdbInterface

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
static private UsbInterface findAdbInterface(UsbDevice device) {
    Log.d(TAG, "findAdbInterface " + device);
    int count = device.getInterfaceCount();
    for (int i = 0; i < count; i++) {
        UsbInterface intf = device.getInterface(i);
        if (intf.getInterfaceClass() == 255 && intf.getInterfaceSubclass() == 66 &&
                intf.getInterfaceProtocol() == 1) {
            return intf;
        }
    }
    return null;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:13,代碼來源:AdbTestActivity.java

示例12: CH34xSerialDevice

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public CH34xSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
    super(device, connection);
    rtsCtsEnabled = false;
    dtrDsrEnabled = false;
    mInterface = device.getInterface(iface >= 0 ? iface : 0);
}
 
開發者ID:BITPlan,項目名稱:can4eve,代碼行數:8,代碼來源:CH34xSerialDevice.java

示例13: CP2102SerialDevice

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public CP2102SerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
    super(device, connection);
    rtsCtsEnabled = false;
    dtrDsrEnabled = false;
    ctsState = true;
    dsrState = true;
    mInterface = device.getInterface(iface >= 0 ? iface : 0);
}
 
開發者ID:BITPlan,項目名稱:can4eve,代碼行數:10,代碼來源:CP2102SerialDevice.java

示例14: PL2303SerialDevice

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public PL2303SerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
    super(device, connection);

    if (iface > 1)
    {
        throw new IllegalArgumentException("Multi-interface PL2303 devices not supported!");
    }

    mInterface = device.getInterface(iface >= 0 ? iface : 0);
}
 
開發者ID:BITPlan,項目名稱:can4eve,代碼行數:12,代碼來源:PL2303SerialDevice.java

示例15: FTDISerialDevice

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public FTDISerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
    super(device, connection);
    ftdiUtilities = new FTDIUtilities();
    rtsCtsEnabled = false;
    dtrDsrEnabled = false;
    ctsState = true;
    dsrState = true;
    firstTime = true;
    mInterface = device.getInterface(iface >= 0 ? iface : 0);
}
 
開發者ID:BITPlan,項目名稱:can4eve,代碼行數:12,代碼來源:FTDISerialDevice.java


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