Android Code Snippet Getting the mount points nailed

Much digging, but what I worked out is this...

B4X:
Sub SDCards As List
    Dim Result As List
    Result.Initialize
    Dim tr As TextReader
    tr.Initialize(File.OpenInput("/proc","mounts"))
    Dim line As String
    Do While True
        line = tr.ReadLine
        If line = Null Then Exit
        ' cols: dev mount type options ......
        Dim Col() As String = Regex.Split(" ",line)
        ' things to ignore
        ' put your false positive mount points here
        If Col(1).StartsWith("/dev") Then Continue
        If Col(1).StartsWith("/proc") Then Continue
        If Col(1).StartsWith("/sys") Then Continue
        If Col(1).StartsWith("/system") Then Continue
        If Col(1).StartsWith("/firmware") Then Continue
        If Col(1).StartsWith("/data") Then Continue
        If Col(1).StartsWith("/mnt/shell") Then Continue
        ' vfat is what we are interested in, but my nexus 5 also uses fuse
        If Col(2) = "vfat" OR Col(2) = "fuse" Then
            Dim s As String = Col(1)
            Result.Add(s)
        End If
    Loop
    tr.Close
    Return Result   
End Sub

It returns a list of mount points. Simple and not limited to one card. It works on all the devices that I have tried.
 

mrred128

Active Member
Licensed User
Longtime User
You can also add the following

B4X:
If File.Exists(Col(1),"Android") Then Continue

if you want to exclude the internal mount point
 

mrred128

Active Member
Licensed User
Longtime User
It's a frustrating topic. I am very glad i was able to make some sense of it. I am umsure why google has not made an api call to get this info. The manufacrures can easily provide the correct information without causing undue stress on the developers.
 

JohnD

Active Member
Licensed User
Longtime User
It's a frustrating topic. I am very glad i was able to make some sense of it. I am umsure why google has not made an api call to get this info. The manufacrures can easily provide the correct information without causing undue stress on the developers.
I hear you. In October '13 when I started developing in b4a, I naively posed the root-access question to my manufacturer's (Samsung) help line. They wouldn't even acknowledge that such a thing existed.
 
Top