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

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

源代码1 项目: FireFiles   文件: UsbStorageProvider.java
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    String deviceName = usbDevice.getDeviceName();
    if (UsbStorageProvider.ACTION_USB_PERMISSION.equals(action)) {
        boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false);
        if (permission) {
            discoverDevice(usbDevice);
            notifyRootsChanged();
            notifyDocumentsChanged(getContext(), getRootId(usbDevice)+ROOT_SEPERATOR);
        } else {
            // so we don't ask for permission again
        }
    } else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)
            || UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
        updateRoots();
    }
}
 
源代码2 项目: FireFiles   文件: UsbStorageProvider.java
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    String deviceName = usbDevice.getDeviceName();
    if (UsbStorageProvider.ACTION_USB_PERMISSION.equals(action)) {
        boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false);
        if (permission) {
            discoverDevice(usbDevice);
            notifyRootsChanged();
            notifyDocumentsChanged(getContext(), getRootId(usbDevice)+ROOT_SEPERATOR);
        } else {
            // so we don't ask for permission again
        }
    } else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)
            || UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
        updateRoots();
    }
}
 
源代码3 项目: FireFiles   文件: UsbStorageProvider.java
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    String deviceName = usbDevice.getDeviceName();
    if (UsbStorageProvider.ACTION_USB_PERMISSION.equals(action)) {
        boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false);
        if (permission) {
            discoverDevice(usbDevice);
            notifyRootsChanged();
            notifyDocumentsChanged(getContext(), getRootId(usbDevice)+ROOT_SEPERATOR);
        } else {
            // so we don't ask for permission again
        }
    } else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)
            || UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
        updateRoots();
    }
}
 
源代码4 项目: UsbGps4Droid   文件: USBGpsSettingsFragment.java
/**
 * Gets a summary of the current select product and vendor ids
 */
private String getSelectedDeviceSummary() {
    int productId = sharedPreferences.getInt(
            USBGpsProviderService.PREF_GPS_DEVICE_PRODUCT_ID, DEFAULT_GPS_PRODUCT_ID);
    int vendorId = sharedPreferences.getInt(
            USBGpsProviderService.PREF_GPS_DEVICE_VENDOR_ID, DEFAULT_GPS_VENDOR_ID);

    String deviceDisplayedName = "Device not connected - " + vendorId + ": " + productId;

    for (UsbDevice usbDevice: usbManager.getDeviceList().values()) {
        if (usbDevice.getVendorId() == vendorId && usbDevice.getProductId() == productId) {
            deviceDisplayedName =
                    "USB " + usbDevice.getDeviceProtocol() + " " + usbDevice.getDeviceName() +
                            " | " + vendorId + ": " + productId;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                deviceDisplayedName = usbDevice.getManufacturerName() + usbDevice.getProductName() +
                        " | " + vendorId + ": " + productId;
            }

            break;
        }
    }

    return deviceDisplayedName;
}
 
源代码5 项目: green_android   文件: BTChipTransportAndroid.java
@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();
	UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
	String deviceName = usbDevice.getDeviceName();

	if (ACTION_USB_PERMISSION.equals(action)) {
		boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,
				false);
           Log.d(LOG_TAG, "ACTION_USB_PERMISSION: " + permission + " Device: " + deviceName);

           // sync with connect
           gotRights.add(permission);
	}
}
 
源代码6 项目: AndroidUSBCamera   文件: USBMonitor.java
/**
		 * this class needs permission to access USB device before constructing
		 * @param monitor
		 * @param device
		 */
		private UsbControlBlock(final USBMonitor monitor, final UsbDevice device) {
			if (DEBUG) Log.i(TAG, "UsbControlBlock:constructor");
			mWeakMonitor = new WeakReference<USBMonitor>(monitor);
			mWeakDevice = new WeakReference<UsbDevice>(device);
			mConnection = monitor.mUsbManager.openDevice(device);
			mInfo = updateDeviceInfo(monitor.mUsbManager, device, null);
			final String name = device.getDeviceName();
			final String[] v = !TextUtils.isEmpty(name) ? name.split("/") : null;
			int busnum = 0;
			int devnum = 0;
			if (v != null) {
				busnum = Integer.parseInt(v[v.length-2]);
				devnum = Integer.parseInt(v[v.length-1]);
			}
			mBusNum = busnum;
			mDevNum = devnum;
//			if (DEBUG) {
				if (mConnection != null) {
					final int desc = mConnection.getFileDescriptor();
					final byte[] rawDesc = mConnection.getRawDescriptors();
					Log.i(TAG, String.format(Locale.US, "name=%s,desc=%d,busnum=%d,devnum=%d,rawDesc=", name, desc, busnum, devnum) + rawDesc);
				} else {
					Log.e(TAG, "could not connect to device " + name);
				}
//			}
		}
 
源代码7 项目: libcommon   文件: USBMonitor.java
/**
		 * 指定したUsbDeviceに関係づけたUsbControlBlockインスタンスを生成する
		 * 内部でopenDeviceをするのでパーミションを取得してないとダメ
		 * @param monitor
		 * @param device
		 */
		private UsbControlBlock(final USBMonitor monitor, final UsbDevice device)
			throws IOException {

//			if (DEBUG) Log.v(TAG, "UsbControlBlock:device=" + device);
			mWeakMonitor = new WeakReference<USBMonitor>(monitor);
			mWeakDevice = new WeakReference<UsbDevice>(device);
			// XXX UsbManager#openDeviceはIllegalArgumentExceptionを投げる可能性がある
			try {
				mConnection = monitor.mUsbManager.openDevice(device);
			} catch (final Exception e) {
				throw new IOException(e);
			}
			final String name = device.getDeviceName();
			if (mConnection != null) {
				final int fd = mConnection.getFileDescriptor();
				final byte[] rawDesc = mConnection.getRawDescriptors();
				Log.i(TAG, String.format(Locale.US,
					"name=%s,fd=%d,rawDesc=", name, fd)
						+ BufferHelper.toHexString(rawDesc, 0, 16));
			} else {
				// 多分ここには来ない(openDeviceの時点でIOException)けど年のために
				throw new IOException("could not connect to device " + name);
			}
			mInfo = UsbDeviceInfo.getDeviceInfo(monitor.mUsbManager, device, null);
			monitor.processConnect(device, this);
		}
 
源代码8 项目: GreenBits   文件: BTChipTransportAndroid.java
@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();
	UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
	String deviceName = usbDevice.getDeviceName();

	if (ACTION_USB_PERMISSION.equals(action)) {
		boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,
				false);
           Log.d(LOG_TAG, "ACTION_USB_PERMISSION: " + permission + " Device: " + deviceName);

           // sync with connect
           gotRights.add(permission);
	}
}
 
源代码9 项目: DeviceConnect-Android   文件: USBMonitor.java
/**
		 * this class needs permission to access USB device before constructing
		 * @param monitor
		 * @param device
		 */
		private UsbControlBlock(final USBMonitor monitor, final UsbDevice device) {
			if (DEBUG) Log.i(TAG, "UsbControlBlock:constructor");
			mWeakMonitor = new WeakReference<USBMonitor>(monitor);
			mWeakDevice = new WeakReference<UsbDevice>(device);
			mConnection = monitor.mUsbManager.openDevice(device);
			mInfo = updateDeviceInfo(monitor.mUsbManager, device, null);
			final String name = device.getDeviceName();
			final String[] v = !TextUtils.isEmpty(name) ? name.split("/") : null;
			int busnum = 0;
			int devnum = 0;
			if (v != null) {
				busnum = Integer.parseInt(v[v.length-2]);
				devnum = Integer.parseInt(v[v.length-1]);
			}
			mBusNum = busnum;
			mDevNum = devnum;
//			if (DEBUG) {
				if (mConnection != null) {
					final int desc = mConnection.getFileDescriptor();
					final byte[] rawDesc = mConnection.getRawDescriptors();
					Log.i(TAG, String.format(Locale.US, "name=%s,desc=%d,busnum=%d,devnum=%d,rawDesc=", name, desc, busnum, devnum) + rawDesc);
				} else {
					Log.e(TAG, "could not connect to device " + name);
				}
//			}
		}
 
源代码10 项目: WalletCordova   文件: BTChipTransportAndroid.java
@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();
	UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
	String deviceName = usbDevice.getDeviceName();

	if (ACTION_USB_PERMISSION.equals(action)) {
		boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,
				false);
           Log.d(LOG_TAG, "ACTION_USB_PERMISSION: " + permission + " Device: " + deviceName);

           // sync with connect
           gotRights.add(permission);
	}
}
 
源代码11 项目: yubikit-android   文件: NoPermissionsException.java
public NoPermissionsException(UsbDevice usbDevice) {
    // with L+ devices we can get more verbal device name
    super("No permission granted to communicate with device " + (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP ? usbDevice.getProductName() : usbDevice.getDeviceName()));
}
 
源代码12 项目: FireFiles   文件: UsbUtils.java
public static String getPath(UsbDevice device){
    return device.getDeviceName();
}
 
源代码13 项目: FireFiles   文件: UsbUtils.java
public static String getPath(UsbDevice device){
    return device.getDeviceName();
}
 
源代码14 项目: FireFiles   文件: UsbUtils.java
public static String getPath(UsbDevice device){
    return device.getDeviceName();
}
 
源代码15 项目: AndroidUSBCamera   文件: USBMonitor.java
/**
 * get device name
 * @return
 */
public String getDeviceName() {
	final UsbDevice device = mWeakDevice.get();
	return device != null ? device.getDeviceName() : "";
}
 
源代码16 项目: USBIPServerForAndroid   文件: UsbIpService.java
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;
}
 
源代码17 项目: UVCCameraZxing   文件: USBMonitor.java
public String getDeviceName() {
	final UsbDevice device = mWeakDevice.get();
	return device != null ? device.getDeviceName() : "";
}
 
源代码18 项目: USBHIDTerminal   文件: USBHIDService.java
@Override
public CharSequence onBuildingDevicesList(UsbDevice usbDevice) {
	return "devID:" + usbDevice.getDeviceId() + " VID:" + Integer.toHexString(usbDevice.getVendorId()) + " PID:" + Integer.toHexString(usbDevice.getProductId()) + " " + usbDevice.getDeviceName();
}
 
源代码19 项目: DeviceConnect-Android   文件: USBMonitor.java
/**
 * get device name
 * @return
 */
public String getDeviceName() {
	final UsbDevice device = mWeakDevice.get();
	return device != null ? device.getDeviceName() : "";
}
 
源代码20 项目: Easycam   文件: SettingsActivity.java
private ArrayList<DeviceEntry> enumerateUsbDevices() {

			ArrayList<DeviceEntry> validStreamingDeviceList = new ArrayList<>(5);

			synchronized (JsonManager.lock) {

				//Make sure the JsonManger has been initialized
				if (!JsonManager.isInitialized())
					JsonManager.initialize();


				// Enumerate a list of currently connected Usb devices so we can pick out which
				// ones are supported easycap devices
				UsbManager mUsbManager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE);
				HashMap<String, UsbDevice> usbDeviceList = mUsbManager.getDeviceList();
				Iterator<UsbDevice> deviceIterator = usbDeviceList.values().iterator();

				// Make sure the device list is empty before enumeration
				validStreamingDeviceList.clear();

				while(deviceIterator.hasNext()) {

					UsbDevice uDevice = deviceIterator.next();

					DeviceInfo devInfo = JsonManager.getDevice(uDevice.getVendorId(), uDevice.getProductId(),
							DeviceInfo.DeviceStandard.NTSC);

					// If a supported device is listed in json list, request permission
					// to access it
					if (devInfo != null) {

						Log.i(TAG, "Supported usb device found: " + uDevice.toString());
						Log.i(TAG, "Device ID: " + uDevice.getDeviceId());
						Log.i(TAG, "Device Name: " + uDevice.getDeviceName());
						Log.i(TAG, "Vendor: ID " + uDevice.getVendorId());
						Log.i(TAG, "Product ID: " + uDevice.getProductId());

						DeviceEntry devEntry = new DeviceEntry();

						devEntry.deviceDescription = devInfo.getDescription() + " @ " + uDevice.getDeviceName();
						devEntry.deviceName = uDevice.getDeviceName() + ":" + devInfo.getVendorID()
								+ ":" + devInfo.getProductID();

						validStreamingDeviceList.add(devEntry);

					}
				}

			}

			return validStreamingDeviceList;
		}