本文整理匯總了Java中android.hardware.usb.UsbDevice.getProductId方法的典型用法代碼示例。如果您正苦於以下問題:Java UsbDevice.getProductId方法的具體用法?Java UsbDevice.getProductId怎麽用?Java UsbDevice.getProductId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.hardware.usb.UsbDevice
的用法示例。
在下文中一共展示了UsbDevice.getProductId方法的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()]);
}
示例2: findUsbSerialPort
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
private UsbSerialPort findUsbSerialPort(ConfigStorage.SerialPortIdentifier identifier) {
final List<UsbSerialDriver> drivers =
UsbSerialProber.getDefaultProber().findAllDrivers(mUsbManager);
for (final UsbSerialDriver driver : drivers) {
for (final UsbSerialPort port : driver.getPorts()) {
UsbDevice device = port.getDriver().getDevice();
if (device != null
&& device.getVendorId() == identifier.getVendorId()
&& device.getProductId() == identifier.getProductId()
&& Objects.equals(device.getSerialNumber(), identifier.getSerialNumber())) {
return port;
}
}
}
return null;
}
示例3: handleException
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
private void handleException(DvbException e) {
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
Collection<UsbDevice> availableDevices = manager.getDeviceList().values();
int[] productIds = new int[availableDevices.size()];
int[] vendorIds = new int[availableDevices.size()];
int id = 0;
for (UsbDevice usbDevice : availableDevices) {
productIds[id] = usbDevice.getProductId();
vendorIds[id] = usbDevice.getVendorId();
id++;
}
response.putExtra(CONTRACT_ERROR_CODE, e.getErrorCode().name());
response.putExtra(CONTRACT_RAW_TRACE, StackTraceSerializer.serialize(e));
response.putExtra(CONTRACT_USB_PRODUCT_IDS, productIds);
response.putExtra(CONTRACT_USB_VENDOR_IDS, vendorIds);
finishWith(RESULT_ERROR);
}
示例4: onReceive
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
//
StringBuilder sb = new StringBuilder();
sb.append("INTENT Action: " + intent.getAction() + "\n");
sb.append("URI: " + intent.toUri(Intent.URI_INTENT_SCHEME).toString() + "\n");
String log = sb.toString();
Log.d(TAG, log);
//
if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if ((device.getVendorId() == sPort.getDriver().getDevice().getVendorId()) &&
(device.getProductId() == sPort.getDriver().getDevice().getProductId())) {
// call your method that cleans up and closes application
Log.d(TAG, "USB_DEVICE_DETACHED: pause SerialConsoleActivity");
SerialConsoleActivity.this.onPause();
}
}
if (new String("usbSerial.action.REBOOT").equals(action)) {
Log.d(TAG, "REBOOT: delayed received");
rebootNow();
}
}
示例5: isSupported
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public static boolean isSupported(UsbDevice device)
{
int vid = device.getVendorId();
int pid = device.getProductId();
if(FTDISioIds.isDeviceSupported(vid, pid))
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;
}
示例6: probeDevice
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
/**
* Probes a single device for a compatible driver.
*
* @param usbDevice the usb device to probe
*
* @return a new {@link UsbSerialDriver} compatible with this device, or
* {@code null} if none available.
*/
@Keep
public UsbSerialDriver probeDevice(final UsbDevice usbDevice) {
final int vendorId = usbDevice.getVendorId();
final int productId = usbDevice.getProductId();
final Class<? extends UsbSerialDriver> driverClass = mProbeTable.findDriver(vendorId, productId);
if (driverClass != null) {
final UsbSerialDriver driver;
try {
final Constructor<? extends UsbSerialDriver> constructor = driverClass.getConstructor(UsbDevice.class);
driver = constructor.newInstance(usbDevice);
} catch (Exception e) {
throw new RuntimeException(e);
}
return driver;
}
return null;
}
示例7: retrieveAvailableUsbDevices
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public static List<RtlSdrDevice> retrieveAvailableUsbDevices(final Context context) {
final List<RtlSdrDevice> result = new LinkedList<>();
if (usbSupported) {
final Object usbManagerObj=context.getSystemService(Context.USB_SERVICE);
if (usbManagerObj instanceof UsbManager) {
final UsbManager manager = (UsbManager) usbManagerObj;
retrieveSupportedDevices(context.getResources());
final HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
for (final Map.Entry<String, UsbDevice> desc : deviceList.entrySet()) {
final UsbDevice candidate = desc.getValue();
final Pair<Integer, Integer> candidatePair = new Pair<>(candidate.getVendorId(), candidate.getProductId());
SupportedDevice device = null;
for (int i = 0; i < supportedDevices.size() && device == null; i++) {
final SupportedDevice supportedDevice = supportedDevices.get(i);
if (supportedDevice.getVendorAndProductId().equals(candidatePair)) {
device = supportedDevice;
}
}
if (device != null) {
final String friendlyName = candidate.getDeviceName() + " " + device.getDescription() + " (" + candidate.getVendorId() + ":" + candidate.getProductId() + ")";
result.add(new RtlSdrDevice(candidate, friendlyName));
}
}
}
}
return result;
}
示例8: onConnect
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
@Override
public void onConnect(UsbDevice device, UsbControlBlock ctrlBlock, boolean createNew) {
int vid = device.getVendorId();
int pid = device.getProductId();
int fd = ctrlBlock.getFileDescriptor();
String usbfs = getUSBFSName(ctrlBlock);
int camid = getDevIdByName(device.getDeviceName());
cameraHandle = V4lJni.openCameraByFd(fd, vid, pid, camid, usbfs, mWidth, mHeight, 0);
}
示例9: onDeviceReady
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
/**
* Called when permission has been granted to a device
* It routes to the appropriate node starting code
*/
private void onDeviceReady(final UsbDevice device) {
// If we got a Kobuki base, save the device pointer and unlock the latch so that the waiting
// ROS node can be launched
mLog.info("Connected device: vendor" + device.getVendorId() + "product: " + device.getProductId());
if (device.getVendorId() == 1027 && device.getProductId() == 24577) {
mUsbDevice = device;
mUsbDeviceLatch.countDown();
}
}
示例10: createUsbSerialDevice
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public static UsbSerialDevice createUsbSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
/*
* It checks given vid and pid and will return a custom driver or a CDC serial driver.
* When CDC is returned open() method is even more important, its response will inform about if it can be really
* opened as a serial device with a generic CDC serial driver
*/
int vid = device.getVendorId();
int pid = device.getProductId();
if(FTDISioIds.isDeviceSupported(vid, pid))
return new FTDISerialDevice(device, connection, iface);
else if(CP210xIds.isDeviceSupported(vid, pid))
return new CP2102SerialDevice(device, connection, iface);
else if(PL2303Ids.isDeviceSupported(vid, pid))
return new PL2303SerialDevice(device, connection, iface);
else if(CH34xIds.isDeviceSupported(vid, pid))
return new CH34xSerialDevice(device, connection, iface);
else if(isCdcDevice(device))
return new CDCSerialDevice(device, connection, iface);
else
return null;
}
示例11: createUsbSerialDevice
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public static UsbSpiDevice createUsbSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
int vid = device.getVendorId();
int pid = device.getProductId();
if(CP2130Ids.isDeviceSupported(vid, pid))
return new CP2130SpiDevice(device, connection, iface);
else
return null;
}
示例12: RPLidarA2Api
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public RPLidarA2Api(UsbManager usbManager) {
Map<String, UsbDevice> connectedDevices = usbManager.getDeviceList();
for (UsbDevice device : connectedDevices.values()) {
if (device.getVendorId() == 0x10c4 && device.getProductId() == 0xea60) {
Log.i(TAG, "Device found: " + device.getDeviceName());
startSerialConnection(usbManager, device);
break;
}
}
}
示例13: isRoyaleDevice
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
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;
}
示例14: enumerateDevices
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
protected void enumerateDevices() {
HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
for (UsbDevice device : deviceList.values()) {
if (device.getVendorId() == BLINK_VENDOR_ID && device.getProductId() == BLINK_PRODUCT_ID) {
if(!mUsbManager.hasPermission(device)) {
mUsbManager.requestPermission(device, mPermIntent);
} else {
setupUsb(device);
}
}
}
}
示例15: getProductId
import android.hardware.usb.UsbDevice; //導入方法依賴的package包/類
public int getProductId() {
final UsbDevice device = mWeakDevice.get();
return device != null ? device.getProductId() : 0;
}