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


Java UsbDevice.getInterfaceCount方法代碼示例

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


在下文中一共展示了UsbDevice.getInterfaceCount方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: dumpDevices

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
/**
 * output device list to LogCat
 */
public final void dumpDevices() {
	final HashMap<String, UsbDevice> list = mUsbManager.getDeviceList();
	if (list != null) {
		final Set<String> keys = list.keySet();
		if (keys != null && keys.size() > 0) {
			final StringBuilder sb = new StringBuilder();
			for (final String key: keys) {
				final UsbDevice device = list.get(key);
				final int num_interface = device != null ? device.getInterfaceCount() : 0;
				sb.setLength(0);
				for (int i = 0; i < num_interface; i++) {
					sb.append(String.format("interface%d:%s", i, device.getInterface(i).toString()));
				}
				Log.i(TAG, "key=" + key + ":" + device + ":" + sb.toString());
			}
		} else {
			Log.i(TAG, "no device");
		}
	} else {
		Log.i(TAG, "no device");
	}
}
 
開發者ID:wjchen,項目名稱:AndroidUvcCameras,代碼行數:26,代碼來源:USBMonitor.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: findFirstCDC

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
private static int findFirstCDC(UsbDevice device)
{
    int interfaceCount = device.getInterfaceCount();

    for (int iIndex = 0; iIndex < interfaceCount; ++iIndex)
    {
        if (device.getInterface(iIndex).getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
        {
            return iIndex;
        }
    }

    Log.i(CLASS_ID, "There is no CDC class interface");
    return -1;
}
 
開發者ID:BITPlan,項目名稱:can4eve,代碼行數:16,代碼來源:CDCSerialDevice.java

示例9: refreshDevice

import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
private final void refreshDevice() {
	if (mUsbMonitor == null) {
		return;
	}
	camList = null;
	List<UsbDevice> allDev = mUsbMonitor.getDeviceList();

	if (allDev.size() <= 0) {
		return;
	}
	
	for (UsbDevice d : allDev) {
		boolean isVideoDev = false;

		if (d.getInterfaceCount() <= 0) {
			if (d.getDeviceClass() == 239 && d.getDeviceSubclass() == 2) {
				isVideoDev = true;
			}
		} else {
			for (int i = 0; i < d.getInterfaceCount(); i++) {
				UsbInterface in = d.getInterface(0);
				if (in == null) {
					continue;
				}
				if (in.getInterfaceClass() == 14) {
					isVideoDev = true;
					break;
				}
			}
		}

		if (isVideoDev) {
			if (camList == null) {
				camList = new ArrayList<UsbDevice>();
			}
			camList.add(d);
		}

	}
	if (camList == null) {
		System.out.println("v4l no device");
	} else {
		Collections.sort(camList, new Comparator<UsbDevice>(){
			@Override
			public int compare(UsbDevice left, UsbDevice right) {
				return (left.getDeviceName().compareTo(right.getDeviceName()));
			}
		});
	}
}
 
開發者ID:wjchen,項目名稱:AndroidUvcCameras,代碼行數:51,代碼來源:CameraPreviewUVC.java


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