3

I am trying to get all available storage which is connected to device, In my device total 3 number of storage available which is (Internal storage, SD Card, OTG storage), how can I identify which one is is OTG?, because Internal storage is non removable storage, and SD card and OTG are both removable storage, how to find from removable storage which one is OTG and which one is SD Card?, below is my code.

fun getAvailableAllStorageVolumes(context: Context): ArrayList<StorageDirectoryParcelable> {
        // Here we gets all storage that are connected to our device
        val volumes = ArrayList<StorageDirectoryParcelable>()
        val sm = context.getSystemService(StorageManager::class.java)

        for (volume in sm.storageVolumes) {
            val path = getVolumeDirectory(volume)
            val name = volume.getDescription(context)
            volumes.add(StorageDirectoryParcelable(path.path, name))

            Log.e("USB","name:- "+ name)
            Log.e("USB","isPrimary:- "+ volume.isPrimary)
            Log.e("USB","isEmulated:- "+ volume.isEmulated)
            Log.e("USB","isRemovable:- "+ volume.isRemovable)
            Log.e("USB","state:- "+ volume.state)
        }
        return volumes
    }   

1 Answers1

0

Try to compare with StorageManager.getPrimaryStorageVolume() it returns the "internal" sdcard volume, so if equals its the sdcard, else its the USB OTG one

Better you can use isPrimary

JHelp
  • 21
  • 4