当前位置: 首页>>代码示例>>Java>>正文


Java UsbInterface.getInterfaceProtocol方法代码示例

本文整理汇总了Java中android.hardware.usb.UsbInterface.getInterfaceProtocol方法的典型用法代码示例。如果您正苦于以下问题:Java UsbInterface.getInterfaceProtocol方法的具体用法?Java UsbInterface.getInterfaceProtocol怎么用?Java UsbInterface.getInterfaceProtocol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.hardware.usb.UsbInterface的用法示例。


在下文中一共展示了UsbInterface.getInterfaceProtocol方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ConnectedUsbDevice

import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
public ConnectedUsbDevice(UsbDeviceConnection connection, UsbInterface usbInterface) {
	this.connection = connection;
	this.usbInterface = usbInterface;
	initConnection(connection);
	int endPoints = usbInterface.getEndpointCount();
	int interfaceProtocol = usbInterface.getInterfaceProtocol();
	System.out.println("EndPoints: " + endPoints + " | interfaces: " + interfaceProtocol);
	out = usbInterface.getEndpoint(1);
	in = usbInterface.getEndpoint(2);
	for (int x = 0; x < endPoints; x++) {
		UsbEndpoint endpoint = usbInterface.getEndpoint(x);
		boolean bulk = endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK;
		boolean crtl = endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_CONTROL;
		boolean inDir = endpoint.getDirection() == UsbConstants.USB_DIR_IN;
		boolean outDir = endpoint.getDirection() == UsbConstants.USB_DIR_OUT;
		System.out.println("ID: " + x + " Bulk: " + bulk + " Ctrl: " + crtl + " Out: " + outDir + " In: " + inDir);
	}
}
 
开发者ID:grundid,项目名称:android-weather-station,代码行数:19,代码来源:ConnectedUsbDevice.java

示例2: findAdbInterface

import android.hardware.usb.UsbInterface; //导入方法依赖的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

示例3: findAdbInterface

import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
static private UsbInterface findAdbInterface(android.hardware.usb.UsbDevice device) {

        int count = device.getInterfaceCount();
        for (int i = 0; i < count; i++) {
            UsbInterface intf = device.getInterface(i);
            if (intf.getInterfaceClass() == 3
                    && intf.getInterfaceSubclass() == 0
                    && intf.getInterfaceProtocol() == 0) {
                return intf;
            }
        }
        return null;
    }
 
开发者ID:MarcProe,项目名称:lp2go,代码行数:14,代码来源:MainActivity.java

示例4: isCamera

import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
/**
 * Tests to see if a {@link android.hardware.usb.UsbDevice}
 * supports the PTP protocol (typically used by digital cameras)
 *
 * @param device the device to test
 * @return true if the device is a PTP device.
 */
static public boolean isCamera(UsbDevice device) {
    int count = device.getInterfaceCount();
    for (int i = 0; i < count; i++) {
        UsbInterface intf = device.getInterface(i);
        if (intf.getInterfaceClass() == UsbConstants.USB_CLASS_STILL_IMAGE &&
                intf.getInterfaceSubclass() == 1 &&
                intf.getInterfaceProtocol() == 1) {
            return true;
        }
    }
    return false;
}
 
开发者ID:asm-products,项目名称:nexus-gallery,代码行数:20,代码来源:MtpClient.java

示例5: filterDevice

import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
private boolean filterDevice(UsbDevice device, JSONArray filters) throws JSONException {
    if (filters == null) {
        return true;
    }
    Log.d(TAG, "filtering " + filters);
    for (int filterIdx = 0; filterIdx < filters.length(); filterIdx++) {
        JSONObject filter = filters.getJSONObject(filterIdx);
        int vendorId = filter.optInt("vendorId", -1);
        if (vendorId != -1) {
            if (device.getVendorId() != vendorId) {
                continue;
            }
        }
        int productId = filter.optInt("productId", -1);
        if (productId != -1) {
            if (device.getProductId() != productId) {
                continue;
            }
        }
        int interfaceClass = filter.optInt("interfaceClass", -1);
        int interfaceSubclass = filter.optInt("interfaceSubclass", -1);
        int interfaceProtocol = filter.optInt("interfaceProtocol", -1);
        if (interfaceClass == -1 && interfaceSubclass == -1 && interfaceProtocol == -1) {
            return true;
        }
        int interfaceCount = device.getInterfaceCount();
        for (int interfaceIdx = 0; interfaceIdx < interfaceCount; interfaceIdx++) {
            UsbInterface usbInterface = device.getInterface(interfaceIdx);
            if (interfaceClass != -1) {
                if (interfaceClass != usbInterface.getInterfaceClass()) {
                    continue;
                }
            }
            if (interfaceSubclass != -1) {
                if (interfaceSubclass != usbInterface.getInterfaceSubclass()) {
                    continue;
                }
            }
            if (interfaceProtocol != -1) {
                if (interfaceProtocol != usbInterface.getInterfaceProtocol()) {
                    continue;
                }
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:MobileChromeApps,项目名称:cordova-plugin-chrome-apps-usb,代码行数:49,代码来源:ChromeUsb.java

示例6: getInfoForDevice

import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
private UsbDeviceInfo getInfoForDevice(UsbDevice dev, UsbDeviceConnection devConn) {
	UsbDeviceInfo info = new UsbDeviceInfo();
	UsbIpDevice ipDev = new UsbIpDevice();
	
	ipDev.path = dev.getDeviceName();
	ipDev.busnum = deviceIdToBusNum(dev.getDeviceId());
	ipDev.devnum =  deviceIdToDevNum(dev.getDeviceId());
	ipDev.busid = String.format("%d-%d", ipDev.busnum, ipDev.devnum);
	
	ipDev.idVendor = (short) dev.getVendorId();
	ipDev.idProduct = (short) dev.getProductId();
	ipDev.bcdDevice = -1;
	
	ipDev.bDeviceClass = (byte) dev.getDeviceClass();
	ipDev.bDeviceSubClass = (byte) dev.getDeviceSubclass();
	ipDev.bDeviceProtocol = (byte) dev.getDeviceProtocol();
	
	ipDev.bConfigurationValue = 0;
	ipDev.bNumConfigurations = 1;
	
	ipDev.bNumInterfaces = (byte) dev.getInterfaceCount();
	
	info.dev = ipDev;
	info.interfaces = new UsbIpInterface[ipDev.bNumInterfaces];
	
	for (int i = 0; i < ipDev.bNumInterfaces; i++) {
		info.interfaces[i] = new UsbIpInterface();
		UsbInterface iface = dev.getInterface(i);
		
		info.interfaces[i].bInterfaceClass = (byte) iface.getInterfaceClass();
		info.interfaces[i].bInterfaceSubClass = (byte) iface.getInterfaceSubclass();
		info.interfaces[i].bInterfaceProtocol = (byte) iface.getInterfaceProtocol();
	}
	
	AttachedDeviceContext context = connections.get(dev.getDeviceId());
	UsbDeviceDescriptor devDesc = null;
	if (context != null) {
		// Since we're attached already, we can directly query the USB descriptors
		// to fill some information that Android's USB API doesn't expose
		devDesc = UsbControlHelper.readDeviceDescriptor(context.devConn);
		
		ipDev.bcdDevice = devDesc.bcdDevice;
		ipDev.bNumConfigurations = devDesc.bNumConfigurations;
	}
	
	ipDev.speed = detectSpeed(dev, devDesc);
	
	return info;
}
 
开发者ID:cgutman,项目名称:USBIPServerForAndroid,代码行数:50,代码来源:UsbIpService.java

示例7: getMassStorageDevices

import android.hardware.usb.UsbInterface; //导入方法依赖的package包/类
/**
 * This method iterates through all connected USB devices and searches for
 * mass storage devices.
 *
 * @param context Context to get the {@link UsbManager}
 * @return An array of suitable mass storage devices or an empty array if none could be found.
 */
public static UsbMassStorageDevice[] getMassStorageDevices(Context context) {
  UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
  ArrayList<UsbMassStorageDevice> result = new ArrayList<UsbMassStorageDevice>();

  for (UsbDevice device : usbManager.getDeviceList().values()) {
    Log.i(TAG, "found usb device: " + device);

    int interfaceCount = device.getInterfaceCount();
    for (int i = 0; i < interfaceCount; i++) {
      UsbInterface usbInterface = device.getInterface(i);
      Log.i(TAG, "found usb interface: " + usbInterface);

      // we currently only support SCSI transparent command set with
      // bulk transfers only!
      if (usbInterface.getInterfaceClass() != UsbConstants.USB_CLASS_MASS_STORAGE
          || usbInterface.getInterfaceSubclass() != INTERFACE_SUBCLASS
          || usbInterface.getInterfaceProtocol() != INTERFACE_PROTOCOL) {
        Log.i(TAG, "device interface not suitable!");
        continue;
      }

      // Every mass storage device has exactly two endpoints
      // One IN and one OUT endpoint
      int endpointCount = usbInterface.getEndpointCount();
      if (endpointCount != 2) {
        Log.w(TAG, "inteface endpoint count != 2");
      }

      UsbEndpoint outEndpoint = null;
      UsbEndpoint inEndpoint = null;
      for (int j = 0; j < endpointCount; j++) {
        UsbEndpoint endpoint = usbInterface.getEndpoint(j);
        Log.i(TAG, "found usb endpoint: " + endpoint);
        if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
          if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
            outEndpoint = endpoint;
          } else {
            inEndpoint = endpoint;
          }
        }
      }

      if (outEndpoint == null || inEndpoint == null) {
        Log.e(TAG, "Not all needed endpoints found!");
        continue;
      }

      result.add(new UsbMassStorageDevice(usbManager, device, usbInterface, inEndpoint,
          outEndpoint));

    }
  }

  return result.toArray(new UsbMassStorageDevice[0]);
}
 
开发者ID:mrolcsi,项目名称:FileBrowser-Android,代码行数:63,代码来源:UsbMassStorageDevice.java


注:本文中的android.hardware.usb.UsbInterface.getInterfaceProtocol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。