Nexus 5 Android 6.0 (API 23) not recognizing OTG flash drive in custom file manager

I’m working on a file manager app that supports OTG flash drives. It runs fine on older Android versions but I’m having trouble with Android 6.0 (Marshmallow) on my Nexus 5.

I’ve added code to handle the new runtime permissions:

void checkPermissions() {
    if (android.os.Build.VERSION.SDK_INT >= 23) {
        String[] perms = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_PHONE_STATE"};
        ArrayList<String> needed = new ArrayList<>();
        
        for (String p : perms) {
            if (checkSelfPermission(p) != PackageManager.PERMISSION_GRANTED) {
                needed.add(p);
            }
        }
        
        if (!needed.isEmpty()) {
            requestPermissions(needed.toArray(new String[0]), 100);
        }
    }
}

I’ve set targetSdkVersion to 23 in my manifest. The app shows permission dialogs at startup, which I accept. But my OTG drive still isn’t readable.

Do I need to do anything else to make OTG work on Android 6.0.1 / Nexus 5? Also, does it matter that I’m not using Android Studio or Gradle?

hey mate, have u tried using UsbManager to detect OTG devices? sometimes android 6 can be picky. also, make sure ur manifest has the USB_HOST feature. i had similar probs and this fixed it for me. good luck!

I have experienced issues with OTG support on Android 6.0 and along with proper runtime permission handling, there are a few extra considerations. In my case, ensuring that the USB host feature is explicitly declared in the manifest helped a lot. I also had to implement device detection using UsbManager and a BroadcastReceiver to fully capture USB events. It is important to test with different cables or even a powered OTG hub since hardware can be unreliable. Although not using Android Studio or Gradle does not inherently cause this issue, using them can simplify managing dependencies and API levels.

Have you considered the storage access framework? In Android 6.0, the way external storage is handled changed significantly. Instead of directly accessing files, you might need to use the Storage Access Framework (SAF) to request permission for specific directories.

Try implementing an intent like this:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, REQUEST_CODE);

Then handle the result in onActivityResult to get a Uri you can use with DocumentFile. This approach has worked well for me when dealing with external storage on Marshmallow and above.

Also, double-check that your device actually supports USB OTG. Some Nexus 5 models had issues with OTG support, so it might be worth testing on a different device to rule out hardware limitations.