Android Question How to get the Volume Label of a storage device?

noeleon

Member
Licensed User
Is there a way to get the Volume label or name of the storage URI returned by the storage access framework?

For example:
content://com.android.externalstorage.documents/tree/8173-1901%3A

The label of that sdcard as shown in file managers is VideoClips, which is what I want my app to use. It would be confusing to the user if my app keeps referring to it as 8173-1901.

Thanks.
 

Erel

Administrator
Staff member
Licensed User
You can get more information about an ExternalFile with this code:
B4X:
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim rs As ResultSet = ctxt.RunMethodJO("getContentResolver", Null).RunMethod("query", Array(f.Native.RunMethod("getUri", Null), Null, Null, Null, Null, Null))
If rs.NextRow Then
   For i = 0 To rs.ColumnCount - 1
       Log($"Column: ${rs.GetColumnName(i)}, value: ${rs.GetString2(i))}"$
   Next
End If
f = ExternalFile
 

noeleon

Member
Licensed User
I was just about to also ask how to get those details of an externalfile :) Thank you for that code.

But I what i'm asking about is the name of the removable storage so that if I ask the user to select a folder in order to get a persistable uri it will be easier to give an instruction like "Swipe from the left edge of the screen then tap VideoClips" instead of saying "tap 8173-1901" because that's nowhere to be seen in the dialog, especially if there's more than 1 removable storage present.

201907102910_163329~02.png
 

noeleon

Member
Licensed User
Oh well... Thank you anyways.

I have one more question: How to convert a URI to ExternalFile?

The URI comes from launching the system file picker through intent
i.Initialize("android.intent.action.GET_CONTENT", "")
 

noeleon

Member
Licensed User
Thank you DonManfred I finally got it after modifying some lines in the ExternalStorage class and using fromSingleUri instead of fromTreeUri
 
Top