Android UsbDevice - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android UsbDevice class.

This code example shows how to use the following methods:getDeviceName
    } 
 
    @Override 
    public void onReceive(Context context, Intent intent) {
        UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
        String deviceName = device.getDeviceName();
        Log.d(TAG, "ACTION_USB_DEVICE_DETACHED " + deviceName);
 
        // close our activity if the device it is displaying is disconnected 
        if (deviceName.equals(mDeviceName)) {
            mActivity.finish();
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getDeviceClass, getDeviceProtocol, getDeviceSubclass, getProductId, getVendorId
            mSubclass = subclass;
            mProtocol = protocol;
        } 
 
        public DeviceFilter(UsbDevice device) {
            mVendorId = device.getVendorId();
            mProductId = device.getProductId();
            mClass = device.getDeviceClass();
            mSubclass = device.getDeviceSubclass();
            mProtocol = device.getDeviceProtocol();
        } 
 
        public static DeviceFilter read(XmlPullParser parser)
                throws XmlPullParserException, IOException { 
            int vendorId = -1;
            int productId = -1;
            int deviceClass = -1;
            int deviceSubclass = -1;
            int deviceProtocol = -1;
 
7
CodeRank
This code example shows how to use the following methods:equals
This code example shows how to use the following methods:getInterface, getInterfaceCount
        super.onDestroy(); 
    } 
 
    private void setDevice(UsbDevice device) {
        Log.d(TAG, "setDevice " + device);
        if (device.getInterfaceCount() != 1) {
            Log.e(TAG, "could not find interface");
            return; 
        } 
        UsbInterface intf = device.getInterface(0);
        // device should have one endpoint 
        if (intf.getEndpointCount() != 1) {
            Log.e(TAG, "could not find endpoint");
            return; 
        } 
        // endpoint should be of type interrupt 
        UsbEndpoint ep = intf.getEndpoint(0);
        if (ep.getType() != UsbConstants.USB_ENDPOINT_XFER_INT) {
            Log.e(TAG, "endpoint is not interrupt type");
            return; 
9
CodeRank
This code example shows how to use the following methods:getDeviceName
    } 
 
    @Override 
    public void onReceive(Context context, Intent intent) {
        UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
        String deviceName = device.getDeviceName();
        Log.d(TAG, "ACTION_USB_DEVICE_DETACHED " + deviceName);
 
        // close our activity if the device it is displaying is disconnected 
        if (deviceName.equals(mDeviceName)) {
            mActivity.finish();
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:equals
This code example shows how to use the following methods:getDeviceClass, getDeviceId, getDeviceName, getInterface, getInterfaceCount
	} 
 
	private void setDevice(UsbDevice device) {
		appendLogText("setDevice " + device);
		 
		appendLogText("getDeviceClass: "+device.getDeviceClass());
		//TODO: finish the mapping 
		switch (device.getDeviceClass()) {
		case UsbConstants.USB_CLASS_APP_SPEC:
			appendLogText("getDeviceClass: USB_CLASS_APP_SPEC "); 
			break; 
		case UsbConstants.USB_CLASS_PER_INTERFACE:
			appendLogText("getDeviceClass: USB_CLASS_PER_INTERFACE"); 
			break; 
		} 
	 
		appendLogText("getDeviceId:" + device.getDeviceId());
		appendLogText("getDeviceName:" + device.getDeviceName());
		appendLogText("getVendorId:" + device.getVendorId());
		appendLogText("getProductId:" + device.getProductId());

6
CodeRank
This code example shows how to use the following methods:getDeviceClass, getDeviceProtocol, getDeviceSubclass
    } 
 
    public static String getClassString(UsbDevice dev) {
        // see http://www.usb.org/developers/defined_class 
        final String name;
        switch (dev.getDeviceClass()) {
            case UsbConstants.USB_CLASS_PER_INTERFACE:
                name = "Periferal";
                break; 
            case UsbConstants.USB_CLASS_AUDIO:
                name = "Audio";
                break; 
            case UsbConstants.USB_CLASS_COMM:
                name = "Comm";
                break; 
            case UsbConstants.USB_CLASS_HID:
                name = "HID";
                break; 
            case UsbConstants.USB_CLASS_PHYSICA:
                name = "PID";

6
CodeRank
This code example shows how to use the following methods:getProductId, getVendorId
  /** 
   * Constructor for default instances of DeviceInfo, populated with numerical IDs rather than 
   * human-readable names. 
   */ 
  public DeviceInfo(UsbDevice device) {
    this(asFourDigitHex(device.getVendorId()), asFourDigitHex(device.getProductId()));
  } 
 
  private DeviceInfo(String vendor, String product) {
    this.vendor = vendor;
    this.product = product;
  } 
 
  public String getVendor() {
    return vendor;
  } 
 
  public String getProduct() {
    return product;
  } 
5
CodeRank
This code example shows how to use the following methods:getProductId, getVendorId
        super(context);
    } 
 
    public void bind(UsbDevice device) {
 
        vendor.setText("" + Integer.toHexString(device.getVendorId()));
        product.setText("" + Integer.toHexString(device.getProductId()));
 
    } 
 
} 
5
CodeRank

Related Android UsbDevice Questions & Answers:

See Code Examples for Android UsbDevice Methods: