android.hardware.usb.UsbDevice#getProductId ( )源码实例Demo

下面列出了android.hardware.usb.UsbDevice#getProductId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: xDrip   文件: SyncingService.java
static public boolean isG4Connected(Context c){
    UsbManager manager = (UsbManager) c.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Log.i("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
                && device.getDeviceProtocol() == 0){
            Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return true;
        }
    }
    return false;
}
 
源代码2 项目: xDrip   文件: SyncingService.java
static public boolean isG4Connected(Context c){
    UsbManager manager = (UsbManager) c.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Log.w("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.w("USB DEVICES = ", String.valueOf(deviceList.size()));

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
                && device.getDeviceProtocol() == 0){
            Log.w("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return true;
        }
    }
    return false;
}
 
源代码3 项目: libcommon   文件: DeviceFilter.java
/**
 * 指定したUsbDeviceがこのDeviceFilterにマッチするかどうかを返す
 * isExcludeフラグは別途#isExcludeか自前でチェックすること
 * @param device
 * @return
 */
public boolean matches(@NonNull final UsbDevice device) {
	if (mVendorId != -1 && device.getVendorId() != mVendorId) {
		return false;
	}
	if (mProductId != -1 && device.getProductId() != mProductId) {
		return false;
	}

	// check device class/subclass/protocol
	if (matches(
		device.getDeviceClass(),
		device.getDeviceSubclass(),
		device.getDeviceProtocol())) {

		return true;
	}

	// check device interface class/interface subclass/interface protocol
	return interfaceMatches(device);
}
 
源代码4 项目: UsbSerial   文件: UsbSerialDevice.java
public static boolean isSupported(UsbDevice device)
{
    int vid = device.getVendorId();
    int pid = device.getProductId();

    if(FTDISioIds.isDeviceSupported(device))
        return true;
    else if(CP210xIds.isDeviceSupported(vid, pid))
        return true;
    else if(PL2303Ids.isDeviceSupported(vid, pid))
        return true;
    else if(CH34xIds.isDeviceSupported(vid, pid))
        return true;
    else if(isCdcDevice(device))
        return true;
    else
        return false;
}
 
源代码5 项目: xDrip-Experimental   文件: SyncingService.java
public UsbDevice findDexcom() {
    Log.i("CALIBRATION-CHECK-IN: ", "Searching for dexcom");
    mUsbManager = (UsbManager) getApplicationContext().getSystemService(Context.USB_SERVICE);
    Log.i("USB MANAGER = ", mUsbManager.toString());
    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
    Log.i("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
                && device.getDeviceProtocol() == 0){
            dexcom = device;
            Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return device;
        } else {
            Log.w("CALIBRATION-CHECK-IN: ", "that was not a dexcom (I dont think)");
        }
    }
    return null;
}
 
源代码6 项目: UVCCameraZxing   文件: DeviceFilter.java
public boolean matches(final UsbDevice device) {
		if (mVendorId != -1 && device.getVendorId() != mVendorId)
			return false;
		if (mProductId != -1 && device.getProductId() != mProductId)
			return false;
/*		if (mManufacturerName != null && device.getManufacturerName() == null)
			return false;
		if (mProductName != null && device.getProductName() == null)
			return false;
		if (mSerialNumber != null && device.getSerialNumber() == null)
			return false;
		if (mManufacturerName != null && device.getManufacturerName() != null
				&& !mManufacturerName.equals(device.getManufacturerName()))
			return false;
		if (mProductName != null && device.getProductName() != null
				&& !mProductName.equals(device.getProductName()))
			return false;
		if (mSerialNumber != null && device.getSerialNumber() != null
				&& !mSerialNumber.equals(device.getSerialNumber()))
			return false; */

		// check device class/subclass/protocol
		if (matches(device.getDeviceClass(), device.getDeviceSubclass(),
				device.getDeviceProtocol()))
			return true;

		// if device doesn't match, check the interfaces
		final int count = device.getInterfaceCount();
		for (int i = 0; i < count; i++) {
			final UsbInterface intf = device.getInterface(i);
			if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(),
					intf.getInterfaceProtocol()))
				return true;
		}

		return false;
	}
 
源代码7 项目: astrobee_android   文件: MainActivity.java
private static boolean isRoyaleDevice(final UsbDevice device) {
    final int vid = device.getVendorId();
    final int pid = device.getProductId();

    if (vid != ROYALE_VENDOR_ID) {
        return false;
    }

    for (int id : ROYALE_PRODUCT_IDS) {
        if (id == pid)
            return true;
    }
    return false;
}
 
源代码8 项目: green_android   文件: BTChipTransportAndroid.java
public static UsbDevice getDevice(UsbManager manager) {
	HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
	for (UsbDevice device : deviceList.values()) {
		if ((device.getVendorId() == VID || device.getVendorId() == VID2) &&
		   ((device.getProductId() == PID_WINUSB) || (device.getProductId() == PID_HID) ||
		    (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE) ||
			(device.getProductId() == PID_NANOX) || (device.getProductId() == PID_HID_LEDGER) ||
			(device.getProductId() == PID_HID_LEDGER_PROTON))) {
			return device;
		}
	}
	return null;		
}
 
源代码9 项目: UsbGps4Droid   文件: USBGpsSettingsFragment.java
/**
 * Updates the list of available devices in the list preference
 */
private void updateDevicesList() {
    HashMap<String, UsbDevice> connectedUsbDevices = usbManager.getDeviceList();
    String[] entryValues = new String[connectedUsbDevices.size()];
    String[] entries = new String[connectedUsbDevices.size()];

    int i = 0;
    // Loop through usb devices
    for (UsbDevice device : connectedUsbDevices.values()) {
        // Add the name and address to the ListPreference entities and entyValues

        String entryValue = device.getDeviceName() +
                " - " + device.getVendorId() + " : " + device.getProductId();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            entryValue = device.getManufacturerName() + " " + device.getProductName() +
                    " - " + device.getVendorId() + " : " + device.getProductId();
        }

        entryValues[i] = device.getDeviceName();
        entries[i] = entryValue;
        i++;
    }

    devicePreference.setEntryValues(entryValues);
    devicePreference.setEntries(entries);
}
 
/**
 * @return the radio device
 */
private UsbDevice getDevice() {
    for (UsbDevice device : usbManager.getDeviceList().values()) {
        if (device.getProductId() == RadioDevice.PRODUCT_ID &&
                device.getVendorId() == RadioDevice.VENDOR_ID) {
            return device;
        }
    }
    return null;
}
 
源代码11 项目: xDrip-plus   文件: UsbTools.java
public static UsbDevice getUsbDevice(final int vendorId, final int productId, final String search) {

        final UsbManager manager = (UsbManager) xdrip.getAppContext().getSystemService(Context.USB_SERVICE);
        if (manager == null) return null;
        final HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
        for (Map.Entry<String, UsbDevice> entry : deviceList.entrySet()) {
            final UsbDevice device = entry.getValue();
            if (device.getVendorId() == vendorId && device.getProductId() == productId
                    && device.toString().contains(search)) {
                Log.d(TAG, "Found device: " + entry.getKey() + " " + device.toString());
                return device;
            }
        }
        return null;
    }
 
源代码12 项目: 600SeriesAndroidUploader   文件: UsbHidDriver.java
public static UsbDevice getUsbDevice(UsbManager usbManager, int vendorId, int productId) {
    // Iterate all the available devices and find ours.
    for (UsbDevice device : usbManager.getDeviceList().values()) {
        if (device.getProductId() == productId && device.getVendorId() == vendorId) {
            return device;
        }
    }

    return null;
}
 
源代码13 项目: GreenBits   文件: BTChipTransportAndroid.java
public static UsbDevice getDevice(UsbManager manager) {
	HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
	for (UsbDevice device : deviceList.values()) {
		if ((device.getVendorId() == VID || device.getVendorId() == VID2) &&
		   ((device.getProductId() == PID_WINUSB) || (device.getProductId() == PID_HID) ||
		    (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE) ||
		    (device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON))) {
			return device;
		}
	}
	return null;		
}
 
源代码14 项目: libcommon   文件: DeviceFilter.java
@SuppressLint("NewApi")
public DeviceFilter(@NonNull final UsbDevice device, final boolean isExclude) {
	mVendorId = device.getVendorId();
	mProductId = device.getProductId();
	mClass = device.getDeviceClass();
	mSubclass = device.getDeviceSubclass();
	mProtocol = device.getDeviceProtocol();
	// getInterfaceCountは内部配列のlengthを返すので負にはならないはずだけど年のために下限を0にする
	final int count = Math.max(device.getInterfaceCount(), 0);
	mIntfClass = new int[count];
	mIntfSubClass = new int[count];
	mIntfProtocol = new int[count];
	for (int i = 0; i < count; i++) {
		final UsbInterface intf = device.getInterface(i);
		mIntfClass[i] = intf.getInterfaceClass();
		mIntfSubClass[i] = intf.getInterfaceSubclass();
		mIntfProtocol[i] = intf.getInterfaceProtocol();
	}
	if (BuildCheck.isLollipop()) {
		mManufacturerName = device.getManufacturerName();
		mProductName = device.getProductName();
		mSerialNumber = device.getSerialNumber();
	} else {
		mManufacturerName = null;
		mProductName = null;
		mSerialNumber = null;
	}
	this.isExclude = isExclude;
}
 
源代码15 项目: DeviceConnect-Android   文件: DeviceFilter.java
/**
	 * 指定したUsbDeviceがこのDeviceFilterにマッチするかどうかを返す
	 * mExcludeフラグは別途#isExcludeか自前でチェックすること
	 * @param device
	 * @return
	 */
	public boolean matches(final UsbDevice device) {
		if (mVendorId != -1 && device.getVendorId() != mVendorId) {
			return false;
		}
		if (mProductId != -1 && device.getProductId() != mProductId) {
			return false;
		}
/*		if (mManufacturerName != null && device.getManufacturerName() == null)
			return false;
		if (mProductName != null && device.getProductName() == null)
			return false;
		if (mSerialNumber != null && device.getSerialNumber() == null)
			return false;
		if (mManufacturerName != null && device.getManufacturerName() != null
				&& !mManufacturerName.equals(device.getManufacturerName()))
			return false;
		if (mProductName != null && device.getProductName() != null
				&& !mProductName.equals(device.getProductName()))
			return false;
		if (mSerialNumber != null && device.getSerialNumber() != null
				&& !mSerialNumber.equals(device.getSerialNumber()))
			return false; */

		// check device class/subclass/protocol
		if (matches(device.getDeviceClass(), device.getDeviceSubclass(), device.getDeviceProtocol())) {
			return true;
		}

		// if device doesn't match, check the interfaces
		final int count = device.getInterfaceCount();
		for (int i = 0; i < count; i++) {
			final UsbInterface intf = device.getInterface(i);
			if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(), intf.getInterfaceProtocol())) {
				return true;
			}
		}

		return false;
	}
 
源代码16 项目: WalletCordova   文件: BTChipTransportAndroid.java
public static UsbDevice getDevice(UsbManager manager) {
	HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
	for (UsbDevice device : deviceList.values()) {
		if ((device.getVendorId() == VID || device.getVendorId() == VID2) &&
		   ((device.getProductId() == PID_WINUSB) || (device.getProductId() == PID_HID) ||
		    (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE) ||
		    (device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON))) {
			return device;
		}
	}
	return null;		
}
 
源代码17 项目: UsbGps4Droid   文件: USBGpsManager.java
private UsbDevice getDeviceFromAttached() {
    debugLog("Checking all connected devices");
    for (UsbDevice connectedDevice : usbManager.getDeviceList().values()) {

        debugLog("Checking device: " + connectedDevice.getProductId() + " " + connectedDevice.getVendorId());

        if (connectedDevice.getVendorId() == gpsVendorId & connectedDevice.getProductId() == gpsProductId) {
            debugLog("Found correct device");

            return connectedDevice;
        }
    }

    return null;
}
 
源代码18 项目: crazyflie-android-client   文件: UsbLinkAndroid.java
public static List<UsbDevice> findUsbDevices(UsbManager usbManager, int vendorId, int productId) {
    List<UsbDevice> usbDeviceList = new ArrayList<UsbDevice>();
    if (usbManager != null) {
        HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
        // Iterate over USB devices
        for (Entry<String, UsbDevice> e : deviceList.entrySet()) {
            Log.i(LOG_TAG, "String: " + e.getKey() + " " + e.getValue().getVendorId() + " " + e.getValue().getProductId());
            UsbDevice device = e.getValue();
            if (device.getVendorId() == vendorId && device.getProductId() == productId) {
                usbDeviceList.add(device);
            }
        }
    }
    return usbDeviceList;
}
 
源代码19 项目: DeviceConnect-Android   文件: USBMonitor.java
/**
 * get product id
 * @return
 */
public int getProductId() {
	final UsbDevice device = mWeakDevice.get();
	return device != null ? device.getProductId() : 0;
}
 
源代码20 项目: DeviceConnect-Android   文件: DeviceFilter.java
@Override
	public boolean equals(final Object obj) {
		// can't compare if we have wildcard strings
		if (mVendorId == -1 || mProductId == -1 || mClass == -1
				|| mSubclass == -1 || mProtocol == -1) {
			return false;
		}
		if (obj instanceof DeviceFilter) {
			final DeviceFilter filter = (DeviceFilter) obj;

			if (filter.mVendorId != mVendorId
					|| filter.mProductId != mProductId
					|| filter.mClass != mClass || filter.mSubclass != mSubclass
					|| filter.mProtocol != mProtocol) {
				return false;
			}
			if ((filter.mManufacturerName != null && mManufacturerName == null)
					|| (filter.mManufacturerName == null && mManufacturerName != null)
					|| (filter.mProductName != null && mProductName == null)
					|| (filter.mProductName == null && mProductName != null)
					|| (filter.mSerialNumber != null && mSerialNumber == null)
					|| (filter.mSerialNumber == null && mSerialNumber != null)) {
				return false;
			}
			if ((filter.mManufacturerName != null && mManufacturerName != null && !mManufacturerName
					.equals(filter.mManufacturerName))
					|| (filter.mProductName != null && mProductName != null && !mProductName
							.equals(filter.mProductName))
					|| (filter.mSerialNumber != null && mSerialNumber != null && !mSerialNumber
							.equals(filter.mSerialNumber))) {
				return false;
			}
			return (filter.isExclude != isExclude);
		}
		if (obj instanceof UsbDevice) {
			final UsbDevice device = (UsbDevice) obj;
			if (isExclude
					|| (device.getVendorId() != mVendorId)
					|| (device.getProductId() != mProductId)
					|| (device.getDeviceClass() != mClass)
					|| (device.getDeviceSubclass() != mSubclass)
					|| (device.getDeviceProtocol() != mProtocol) ) {
				return false;
			}
/*			if ((mManufacturerName != null && device.getManufacturerName() == null)
					|| (mManufacturerName == null && device
							.getManufacturerName() != null)
					|| (mProductName != null && device.getProductName() == null)
					|| (mProductName == null && device.getProductName() != null)
					|| (mSerialNumber != null && device.getSerialNumber() == null)
					|| (mSerialNumber == null && device.getSerialNumber() != null)) {
				return (false);
			} */
/*			if ((device.getManufacturerName() != null && !mManufacturerName
					.equals(device.getManufacturerName()))
					|| (device.getProductName() != null && !mProductName
							.equals(device.getProductName()))
					|| (device.getSerialNumber() != null && !mSerialNumber
							.equals(device.getSerialNumber()))) {
				return (false);
			} */
			return true;
		}
		return false;
	}