Android Question ExternalStorage - where is the folder?

Hello!
After selecting a folder, I change my interface. For example, I display the Micro SD or Phone icon on the screen, depending on where I am.
How can I determine this in the program?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
In fact, everything is much simpler.
ExternalStorage stores the information I need in the PersistantUri.
Thus, after selecting a folder, our location is stored in this file.

It is enough to do a simple analysis:
1. Find out if there is an SD card at all.
2. Find out its distinctive feature - let's call it "Identifier".

B4X:
Sub Which_Storage As Boolean
    'Define Storage: Phone storage (=true) or SD card (false).
    Dim AllExternal() As String = rpRuntimePermissions.GetAllSafeDirsExternal("")
    Dim PersistantUri As String
    Dim ExternalDir As String        'External storage.
    Dim sText As String            'The "Identifier" of the folder.
    Dim iPos As Int
    
    'Read the contents of the PersistantUri file - the URI of the previous (current) folder.
    PersistantUri = File.ReadString(File.DirInternal, "PersistantUri")

    sText = PersistantUri
    'Delete the text on the right, starting with "%".
    sText = sf.Left(sText, sf.InString(sText, "%"))
    'Delete all texts containing "/" on the left.
    iPos = sf.InString(sText, "/")
    Do While iPos>=0
        sText = sf.Right(sText, sText.Length-iPos-1)
        'Log("sText - " & sText)
        'Log("Stop")
        iPos = sf.InString(sText, "/")
    Loop

    'We form the "Identifier" of the folder.
    sText = "/" & sText
    
    If AllExternal.Length >1 Then
        'There is an external SD card.
        ExternalDir = AllExternal(1)
        If sf.InString(ExternalDir, sText) >= 0 Then
            'The current folder is on the SD card.
            Return False
        Else
            'The current folder is in Phone Memory.
            Return True
        End If
    Else
        'No SD card.
        Return True
    End If
End Sub

Actually, that's enough for me.
 
Upvote 0
Top