Android Question Identify SD card or USB pendrive

rosippc64a

Active Member
Licensed User
Longtime User
Hi All,
I can successfully read folder structure of sd card or usb pendrive like this:
B4X:
        Log(File.ListFiles("/storage"))
I use only one type of android device, so the /storage is ok.
I can sense attaching and removing on the fly.
But:
The result of the directory listing looks like that:
B4X:
/storage/3E98-DF1D
/storage/3E98-DF1D/Android
/storage/3E98-DF1D/LOST.DIR
/storage/3E98-DF1D/Wilbur Smith - A fáraó
/storage/424610224610196D
/storage/424610224610196D/Android
/storage/424610224610196D/NEM_MP3_KÖNYVEK2
/storage/424610224610196D/System Volume Information
/storage/emulated
/storage/self
How can I identify which is the sd card and which is the usb pendrive (3E98-DF1D/424610224610196D)?
thanks in advance
Steven
 

Mahares

Expert
Licensed User
Longtime User
How can I identify which is the sd card and which is the usb pendrive (3E98-DF1D/424610224610196D)?
Try this with runtime permissions: need runtime permission lib.
B4X:
For Each s As String In rp.GetAllSafeDirsExternal("")  'returns a string array
        Log(s)  '1st media is always the defaultExternal, 2nd is the physical SD card, 3rd if accessible probably USB pendrive
Next
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
what if there is no sd card? Then the second will be the usb pendrive!
I have tested it only as far as a device with and SD card and no USB drive and it worked for me. When there is no SD card, it just returned the default External and no error. Try it with a device without SD but with USB and see what happens. I am guessing it will return the USB drive as the 2nd.
 
Last edited:
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Sorry, but the order isn't relevant:
B4X:
    Dim rp As RuntimePermissions
    For Each s As String In rp.GetAllSafeDirsExternal("")  'returns a string array
        Log(s)  '1st media is always the defaultExternal, 2nd is the physical SD card, 3rd if accessible probably USB pendrive
    Next
    '1. inner memory + sd card:
'    /storage/emulated/0/Android/data/com.misiolvas/files
'    /storage/3E98-DF1D/Android/data/com.misiolvas/files '<--sd card
'    2. inner memory + sd card + pendrive1
'    /storage/emulated/0/Android/data/com.misiolvas/files
'    /storage/3E98-DF1D/Android/data/com.misiolvas/files '<--sd card
'    /storage/424610224610196D/Android/data/com.misiolvas/files '<--pendrive1
'    3. inner memory + sd card + pendrive1 + pendrive2
'    /storage/emulated/0/Android/data/com.misiolvas/files
'    /storage/6C4A-711A/Android/data/com.misiolvas/files '<--pendrive2
'    /storage/3E98-DF1D/Android/data/com.misiolvas/files '<--sd card
'    /storage/424610224610196D/Android/data/com.misiolvas/files '<--pendrive1
'    4. inner memory + pendrive + pendrive2
'    /storage/emulated/0/Android/data/com.misiolvas/files
'    /storage/6C4A-711A/Android/data/com.misiolvas/files '<--pendrive2
'    /storage/424610224610196D/Android/data/com.misiolvas/files '<--pendrive1
'    5. inner memory + pendrive2
'    /storage/emulated/0/Android/data/com.misiolvas/files
'    /storage/6C4A-711A/Android/data/com.misiolvas/files '<--pendrive2
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Thank you Erel, but my problem isn't that how to access the sd card and usb pendrive, that works well. My problem that, how to identify which is which? By the way, that program is for visually impaired persons, notably for blinds, so they can't manually select the mass storage.
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
This program can give voice report about sd card or usb pendrive(s) for blind persons to select one and it would be good to hear if select inserted sd card or pendrive. Now I can report only '1. external device' or '2. external device', etc.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Sorry, but the order isn't relevant:
I looked at your tests and the order is relevant when you have only one pen drive: (default ext, SD, Pen Drive). Can you limit your application to just use one pen drive.
1. inner memory + sd card:
/storage/emulated/0/Android/data/com.misiolvas/files
/storage/3E98-DF1D/Android/data/com.misiolvas/files '<--sd card

2. inner memory + sd card + pendrive1
/storage/emulated/0/Android/data/com.misiolvas/files
/storage/3E98-DF1D/Android/data/com.misiolvas/files '<--sd card
/storage/424610224610196D/Android/data/com.misiolvas/files '<--pendrive1

5. inner memory + pendrive2
/storage/emulated/0/Android/data/com.misiolvas/files
/storage/6C4A-711A/Android/data/com.misiolvas/files '<--pendrive2

Your original question was: How can I identify which is the sd card and which is the usb pendrive (3E98-DF1D/424610224610196D)?
 
Upvote 0
Top