I'm developing an app where I can delete files from the SD Card, and I also want to display the SD Card label, NOT the SD Card path, as there is a lot of informations on this already, but not that much about External Storage name. When I'm talking about SD Card name, I mean the thing that is showed up when you mount it on a PC and in your file explorer it shows you the name of it like "John D SD Card"
Any help about that would be appreciated ! Thanks
For Android 7/N and up:
StorageManager sm = (StorageManager)getSystemService(Context.STORAGE_SERVICE);
List<StorageVolume> volumes = sm.getStorageVolumes();
StringBuilder sb = new StringBuilder();
int nr = -1;
while (++nr < volumes.size() )
{
StorageVolume volume = volumes.get(nr);
sb.append(volume.getUuid()).append("\n");
sb.append(volume.getState()).append("\n");
//sb.append(volume.EXTRA_STORAGE_VOLUME + "\n");
sb.append(volume.getDescription(context)).append("\n");
sb.append(volume.toString()).append("\n");
if ( VERSION.SDK_INT >= Build.VERSION_CODES.R)
sb.append(volume.getDirectory()).append("\n");
sb.append( "\n");
}
Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG).show();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.