Getting the information for a USB drive connected to Android tablet

71 Views Asked by At

I have the following code in C#.

var drives = DriveInfo.GetDrives();
var removableDrive = drives.Where(d => d.DriveFormat != null && d.DriveFormat.Contains("msdos")).FirstOrDefault();

                    
if (removableDrive != null)
{
    int megaBytesAvaialble = Convert.ToInt32(removableDrive?.AvailableFreeSpace / 1000000);
    _exportService.AvaialbleFreeSpace = megaBytesAvaialble;
                      
}

I am connecting a PCMCIA card to the tablet via a USB-C to USB adapter. The PCMCIA Card is 1GB. I need to check that there is at least 40MB free on the card for our app to write data to the card. The code works for Android 13 but not Android 11. Is there a way to get the drive information for the USB drive in order to find the available free space in both versions of android?

For the code above, the DriveFormat is showing "Unknown" in Android 11. That is the reason it is not working. The drive format is "msdos" in Android 13.

I have tried using the Broadcast Receiver. Things I have found to try their do not get the information from the USB drive that I am connecting. I am getting information from the SD card or the internal storage.

0

There are 0 best solutions below