Java Code Examples for android.hardware.usb.UsbDevice#equals()

The following examples show how to use android.hardware.usb.UsbDevice#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractBackgroundUsbService.java    From external-nfc-api with Apache License 2.0 6 votes vote down vote up
public void onReceive(Context context, Intent intent) {

            String action = intent.getAction();

            if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {

                Log.d(TAG, "Usb device detached");

                synchronized (this) {
                    UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

                    if (device != null && device.equals(reader.getDevice())) {
                        // Close reader
                        Log.d(TAG, "Closing reader " + reader.getReaderName());

                        new CloseTask().execute();
                    }
                }
            }
        }
 
Example 2
Source File: MainActivity.java    From Android-Webcam with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState != null) {
        openDevice = savedInstanceState.getParcelable(KEY_OPEN_DEVICE);
    }

    deviceDisconnectedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (webcam == null) {
                return;
            }

            final UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
            if (usbDevice.equals(webcam.getDevice())) {
                Timber.d("Active Webcam detached. Terminating connection.");
                stopStreaming();
            }
        }
    };
}
 
Example 3
Source File: UsbStorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void discoverDevice(UsbDevice device) {
    for (UsbMassStorageDevice massStorageDevice : UsbMassStorageDevice.getMassStorageDevices(getContext())) {
        if (device.equals(massStorageDevice.getUsbDevice())) {
            if (hasPermission(device)) {
                addRoot(massStorageDevice);
            } else {
                requestPermission(device);
            }
        }
    }
}
 
Example 4
Source File: UsbStorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void discoverDevice(UsbDevice device) {
    for (UsbMassStorageDevice massStorageDevice : UsbMassStorageDevice.getMassStorageDevices(getContext())) {
        if (device.equals(massStorageDevice.getUsbDevice())) {
            if (hasPermission(device)) {
                addRoot(massStorageDevice);
            } else {
                requestPermission(device);
            }
        }
    }
}
 
Example 5
Source File: UsbStorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private void discoverDevice(UsbDevice device) {
    for (UsbMassStorageDevice massStorageDevice : UsbMassStorageDevice.getMassStorageDevices(getContext())) {
        if (device.equals(massStorageDevice.getUsbDevice())) {
            if (hasPermission(device)) {
                addRoot(massStorageDevice);
            } else {
                requestPermission(device);
            }
        }
    }
}
 
Example 6
Source File: USBMonitor.java    From AndroidUSBCamera with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(final Object o) {
	if (o == null) return false;
	if (o instanceof UsbControlBlock) {
		final UsbDevice device = ((UsbControlBlock) o).getDevice();
		return device == null ? mWeakDevice.get() == null
				: device.equals(mWeakDevice.get());
	} else if (o instanceof UsbDevice) {
		return o.equals(mWeakDevice.get());
	}
	return super.equals(o);
}
 
Example 7
Source File: USBMonitor.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(final Object o) {
	if (o == null) return false;
	if (o instanceof UsbControlBlock) {
		final UsbDevice device = ((UsbControlBlock) o).getDevice();
		return device == null ? mWeakDevice.get() == null
				: device.equals(mWeakDevice.get());
	} else if (o instanceof UsbDevice) {
		return o.equals(mWeakDevice.get());
	}
	return super.equals(o);
}
 
Example 8
Source File: USBMonitor.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public boolean equals(final Object o) {
	if (o == null) return false;
	if (o instanceof UsbControlBlock) {
		final UsbDevice device = ((UsbControlBlock) o).getDevice();
		return device == null ? mWeakDevice.get() == null
				: device.equals(mWeakDevice.get());
	} else if (o instanceof UsbDevice) {
		return o.equals(mWeakDevice.get());
	}
	return super.equals(o);
}
 
Example 9
Source File: DualCameraPreview.java    From AndroidUsbCamera with Apache License 2.0 5 votes vote down vote up
@Override
public void onDisconnect(UsbDevice device, USBMonitor.UsbControlBlock ctrlBlock) {
    if(DEBUG) Log.v(TAG, "onDisconnect" + device);
    if(mCameraLeft != null && device.equals(mCameraLeft.getDevice())){
        releaseUVCCamera(0);
    }
    if(mCameraRight != null && device.equals(mCameraRight.getDevice())){
        releaseUVCCamera(1);
    }
}
 
Example 10
Source File: SingleCameraPreview.java    From AndroidUsbCamera with Apache License 2.0 5 votes vote down vote up
@Override
public void onDisconnect(UsbDevice device, USBMonitor.UsbControlBlock ctrlBlock) {
    if(DEBUG) Log.v(TAG, "onDisconnect" + device);
    if(mCamera != null && device.equals(mCamera.getDevice())){
        releaseUVCCamera();
    }
}