Search in sources :

Example 1 with UsbOtgRepresentation

use of com.amaze.filemanager.file_operations.filesystem.usb.UsbOtgRepresentation in project AmazeFileManager by TeamAmaze.

the class MainActivity method updateUsbInformation.

/**
 * Updates everything related to USB devices MUST ALWAYS be called after onResume()
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void updateUsbInformation() {
    boolean isInformationUpdated = false;
    List<UsbOtgRepresentation> connectedDevices = OTGUtil.getMassStorageDevicesConnected(this);
    if (!connectedDevices.isEmpty()) {
        if (SingletonUsbOtg.getInstance().getUsbOtgRoot() != null && OTGUtil.isUsbUriAccessible(this)) {
            for (UsbOtgRepresentation device : connectedDevices) {
                if (SingletonUsbOtg.getInstance().checkIfRootIsFromDevice(device)) {
                    isInformationUpdated = true;
                    break;
                }
            }
            if (!isInformationUpdated) {
                SingletonUsbOtg.getInstance().resetUsbOtgRoot();
            }
        }
        if (!isInformationUpdated) {
            SingletonUsbOtg.getInstance().setConnectedDevice(connectedDevices.get(0));
            isInformationUpdated = true;
        }
    }
    if (!isInformationUpdated) {
        SingletonUsbOtg.getInstance().resetUsbOtgRoot();
        drawer.refreshDrawer();
    }
    // Registering intent filter for OTG
    IntentFilter otgFilter = new IntentFilter();
    otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mOtgReceiver, otgFilter);
}
Also used : IntentFilter(android.content.IntentFilter) UsbOtgRepresentation(com.amaze.filemanager.file_operations.filesystem.usb.UsbOtgRepresentation) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

IntentFilter (android.content.IntentFilter)1 RequiresApi (androidx.annotation.RequiresApi)1 UsbOtgRepresentation (com.amaze.filemanager.file_operations.filesystem.usb.UsbOtgRepresentation)1